Original Post
I have a single function that opens a file, then finds the length of it, then creates a pointer and allocates enough space before reading the file contents into it. The function then returns with the pointer holding the data to this file for further access outside of the function. The problem I have is when I''m done using this file in memory, were do I delete it so I don''t have a memory leak? Right now I''m deleting it outside the function when I''m done using it.
Am I better off creating a pointer outside this function first and then sending the pointer to this function were the function will allocate enough space to hold the contents of this file? Either way I still have to delete it outside of the function. Also because I''m calling this function several times, I can''t have it as global.
So what I''m asking is, what''s the best way to do this.