Original Post
Hi,
I''ve been running into this same problem lately and for years I''ve just been working around it without really figuring out a good way to deal with it... The problem is how to write a function which loads an array of something..
For example, I''m writing a function which loads a bunch of vertices into an array... So of course, I guess I have to make the user pass the array to me from which I will create the vertices, because if you try to dynamically create the array from within the function, that causes a memory leak (since the client of the function doesn''t know to delete this memory).
But, on the other hand, if I have the client pass in a buffer to store the vertices in, that doesn''t make sense either because the client won''t know how big to make the buffer since that depends on the file being loaded!
So far, in these cases my approach has just been to return a pointer from the function, and assume the user will delete it later, like this:
char *img = load_bitmap("blah.bmp");
...
delete [] img;
This is okay I guess, but does anyone know of a more elegant way to handle this? If you would, I''d really appreciate any tips. Thanks a lot!
Rajan