See interspersed
On 9/30/11 10:31 PM, sravanreddy001 wrote:
> [THERE ARE MANY QUESTIONS. PLEASE REPLY TO ANYTHING YOU WANT TO.]
> [THANKS IN ADVANCE.]
>
> Hi Noah,Richard:
>
> Both your answers were helpful for my understanding.
>
> Noah: True, I'm working in some performance issues and dealing with lot of small files..
> total of 150,000 files, and creating multiple vectors in each iteration.
>
> The amount memory I'm saving is very less may be around 10 MB.. max 15 MB not more than that..
>
> But, my applications starts and grows over 500MB.
> I'm thinking there might some memory leak, or its equivalent.
>
> How could that be?
>
> most of my code structure is like this.
>
>
> for(i=0;i<150000;i++){
> vector<string> data;
>
> // read from files, store into data.
> //and write 'data' to another file.
>
vector, and the strings in it, will be destroyed here, when the loop
exits the context of the body of the loop.
> }
>
>
> QUESTION: Is it mandatory to erase the contents in the next loop, or this is automatically handled by compiler/runtime/OS.
>
> working in unix. I'm also creating soo many strings like
>
> string str = //some source;
>
> are these also released after each run?
>
> --> At some places, I'm reading file in one go. by creating memory using 'malloc'. Should this be released explicitly?
All memory you allocate from the heap needs to be deallocated. Automatic
variables are deallocated when you leave their scope.
If you allocate memory, and do not put it into something that is smart
enough to automatically deallocate it for you, then you need to do the
deallocation yourself. "Smart Pointers" are one method to make sure the
memory is deallocated, but they default to assuming the memory was
allocated with new, not malloc. (but some can be told how to deallocate
the object). containers will destroy the object put in them, but if they
are holding pointers, that destroys the POINTER, not the pointed to object.
>
>
> If any one of you can help me with similar stuff, please drop a mail to sravanreddy001 @ gmail.com I wont bother you
|