Saturday, May 21, 2011

Alloc so far so good

This worked the first time which is a good sign that some stuff I see over and over again but don't actually use sticks!

The output is: Storage is at 0x808e008 and is size 4

...and the address naturally changes run to run.
So the program for getting data out of a file will return an address of where the data is stored. That's what malloc is for right? Put data into the heap and that data remains until freed (oh snap I just realized I never freed my array in the program above...) regardless of where it was allocated (like it won't go out of scope unless the variable storing the address goes out of scope before being passed out of the function).

This has the double benefit of delivering the data and allowing for knowing how many elements is in the stored space (proved with my use of sizeof).

So, hooray.

No comments:

Post a Comment