Data structures to use within DLL

I need some guidance regarding the architecture and data types to use within a DLL that I have been assigned to write. I apologize since it will lead me to asking a number of questions in a single thread. Also this is my first forum post ever, forgive me if I miss something out.

To simplify my question, consider-

My DLL gets pointers to 3 arrays: PointsX, PointsY and PointsZ (cartesian coordinates). The number of elements can be large (usually 20000, max 64000) and have a floating point.

Each of the 3 arrays are then split into smaller arrays which I will call segments. The number of segments is variable and so are their sizes.
eg. PointsX split into PointsXSegment1, PointsXSegment2 and PointsXSegment3
Each segment array in turn is interpolated and its size may increase (sometimes almost double the original size) and then filtered.

Finally, these segments are to be returned to the calling program.

Questions
1) Memory. I have had trouble creating these huge arrays.
main()
{
double PointsX[64000];
}
gives out of memory error.
So I tried to reduce my footprint by
float PointsX[2000];
main()
{}
i.e. make a global declaration to allocate memory on heap, change type to float and reduce array size. What strategies can I use to keep my array type double?

2) Are arrays the best way to go? Should I use structures or some other data-types? Would dynamic memory allocation help?

3) How do I send the individual segment arrays back to the calling program? String them all together in one giant array and send segment begin and end numbers? Or declare a bunch of null pointers and set them to segment arrays once they are created?
If you need contiguous memory, then yes, use arrays.

Don't declare them on the stack as in 1), get them from the heap. The stack is relatively small, and even though it grows dynamically on WIN32, it's there to manage functions, not to be used as a data segment.

Depending on what you're doing, you can use the C++ global allocator (new) or go straight to the OS for memory. I expect you'd use the former.
1, 2) Yes, use arrays. Obtain them dynamically.

3) The calling program and the DLL share the same memory space, so all you need is to pass a pointer to the data you allocate.

You need to be careful, however, not to use new[] in the DLL and delete[] in the calling program, or vice-versa. The EXE and the DLL do not share memory management!

You need to explicitly specify what is OK and what is not OK. Two common methods follow:

method one
Use Windows API functions to allocate and deallocate memory, so that the calling process can do the same with memory managed by the DLL. The Win32 functions you need are HeapAlloc(), HeapFree(), and even HeapReAlloc().
http://www.google.com/search?btnI=1&q=msdn+HeapAlloc
This way, both EXE and DLL can manipulate the memory - since we're using the OS's memory management functions.

method two
Export a function specifically to deallocate memory (and more, as you wish) - which the caller is required to use to handle memory you give it. That way the code for your DLL can use new[] and delete[], or malloc() and free(), or whatever you want, and the caller can use whatever it wants, since neither directly allocates or deallocates the other's memory.

Hope this helps.
Thank you for your replies. I will read up on the points that you make (I'm pretty new to programming) and post my results soon.
I just used new[] and delete[] within the DLL and it seems to work fine now. Thank you very much!
Topic archived. No new replies allowed.