Sunday, March 27, 2011

goals for today

I was right about gnuplot_i.c. It wasn't looking in the right place for the gnuplot executable. The function in question claims that it works a lot like "which" but when I remove gnuplot from /usr/bin the "which" command finds it in /usr/local/bin, so I don't know.

Anyways, today I am going to work on dynamic memory allocation.

The file reading program right now just spits out samples to printf and doesn't store them. I'd like to find a way to dump the samples to somewhere in memory then give back the location of that memory.

What I need to figure out is this:

1) Should I pre-allocate memory in main() and then pass a pointer to that memory to my function? If so, I guess I have to create a new function that scans the file and figures out how much memory I'd need to allocate.

2) Lets say I do the allocation in my reader function and pass back a pointer to that memory location - the pointer is still valid after the function ends, right? If I allocate memory with malloc() and pass out a pointer to that memory I think it will be legit until I free() that memory... I'll have to test that.

3) How do I know what the end of the memory is? Do I need to keep track of how deep I am when reading into the data I stored, or is there a /0 to look out for? I feel like I should know that already.

I'll probably build up a test program to make sure I'm doing things sanely before diving into my real program.

No comments:

Post a Comment