DMA Question - is this okay to do?
Displaying 1-4 of 4 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
mr_blister

int p = malloc(whatever);
...
...
...
int j = p;
...
...
...
...
MemFree(j);

This should work, right? I tried looking in the docs but couldn't see anything...

Posted on 2005-11-12 08:20:06

Omni

You got it, that will work just fine. P is assigned a handle to the malloc-ed space, and you can assign that same handle to J.

Once you free the handle through J, though...don't try to access it again with P, of course, because they both point to the same handle, and the handle would be empty.

Posted on 2005-11-12 08:57:29

mr_blister

Yeah, I assumed it would work, but wanted to be sure. I'm trying to code a set of DMA structures like Stacks and Maps that people can put anything into, like Dynamic strings and other dynamically created stuff.

So when the structures are destroyed, the stuff in the structure is destroyed too, like:


int elem;

for each element i in structure
elem = ith element;
MemFree(elem);
next

MemFree(the actual DMA structure)


Ultimately, I want to be super sure my structures would be able to handle anything users put in, so they define their own destructor. A default one would be available that acts as if the structure contains just ints, no dynamic stuff. Sort of like:


int DMA_ELEM; // Represents each element in the structure.

void default_destroy() {}

void user_destroy()
{
// do to DMA_ELEM whatever you need to do to
// free it properly
}

.....

int myset = DMA_Set_create();

DMA_Set_SetDestructor(DMA_String_Create("user_destroy"));

.....
// Destructor loop...

string behaviour = DMA_String_ToNative( *PULL OUT OF STRUCTURE* );
for each element i in structure
DMA_ELEM = ith element;
CallFunction(behaviour)
next

MemFree(the actual DMA structure)

Posted on 2005-11-12 09:12:17

Omni

Interesting...

Posted on 2005-11-12 09:51:00


Displaying 1-4 of 4 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.