Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #10617 > unrolled thread
| Started by | sravanreddy001 <sravanreddy001@gmail.com> |
|---|---|
| First post | 2011-09-30 15:42 -0700 |
| Last post | 2011-09-30 23:14 -0400 |
| Articles | 5 — 3 participants |
Back to article view | Back to comp.lang.c++
Small question with respect to scope and performace sravanreddy001 <sravanreddy001@gmail.com> - 2011-09-30 15:42 -0700
Re: Small question with respect to scope and performace Richard Damon <news.x.richarddamon@xoxy.net> - 2011-09-30 19:22 -0400
Re: Small question with respect to scope and performace Noah Roberts <roberts.noah@gmail.com> - 2011-09-30 15:51 -0700
Re: Small question with respect to scope and performace sravanreddy001 <sravanreddy001@gmail.com> - 2011-09-30 19:31 -0700
Re: Small question with respect to scope and performace Richard Damon <news.x.richarddamon@xoxy.net> - 2011-09-30 23:14 -0400
| From | sravanreddy001 <sravanreddy001@gmail.com> |
|---|---|
| Date | 2011-09-30 15:42 -0700 |
| Subject | Small question with respect to scope and performace |
| Message-ID | <27725376.29.1317422561029.JavaMail.geo-discussion-forums@yqbu18> |
Hi, I have small doubt. There are two functions. 1) stores lot of data.. atleast 100 MB 2) another doesn't use above data. so, if 2 is called from 1. where the contents of 1 be moved to stack? and 2. is called? In that case, does maintaining the data as global values, will reduce that overhead? (Security of data can be managed and not an issue) Thanks, Sravan.
[toc] | [next] | [standalone]
| From | Richard Damon <news.x.richarddamon@xoxy.net> |
|---|---|
| Date | 2011-09-30 19:22 -0400 |
| Message-ID | <j65j00$nas$1@dont-email.me> |
| In reply to | #10617 |
On 9/30/11 6:42 PM, sravanreddy001 wrote: > Hi, > > I have small doubt. > > There are two functions. > 1) stores lot of data.. atleast 100 MB > 2) another doesn't use above data. > > so, if 2 is called from 1. > where the contents of 1 be moved to stack? and 2. is called? > > In that case, does maintaining the data as global values, will reduce that overhead? (Security of data can be managed and not an issue) > > Thanks, > Sravan. If 1 stores its data on the stack, it will be there once the function creates it, and not "moved" there when 2 is called, so there is no overhead there. If 1 stores its data else where, it won't be moved there either. To be pedantic, actually this isn't the way the standard says it, because the standard never refers to "the stack". Typical implementation though is to place variables of storage class "auto" (as opposed to global, static or objects created on the heap) on the stack. 100 MB of data is large to be all "on the stack" (but possible), but my guess is that much of this data is apt to be in containers, where the control structure for the container may be on the stack, but most of the data will be on the heap.
[toc] | [prev] | [next] | [standalone]
| From | Noah Roberts <roberts.noah@gmail.com> |
|---|---|
| Date | 2011-09-30 15:51 -0700 |
| Message-ID | <a50b3eb3-7fa6-42c2-abdb-3078b3dd6537@h34g2000yqd.googlegroups.com> |
| In reply to | #10617 |
On Sep 30, 3:42 pm, sravanreddy001 <sravanreddy...@gmail.com> wrote: > Hi, > > I have small doubt. > > There are two functions. > 1) stores lot of data.. atleast 100 MB > 2) another doesn't use above data. > > so, if 2 is called from 1. > where the contents of 1 be moved to stack? and 2. is called? > > In that case, does maintaining the data as global values, will reduce that overhead? (Security of data can be managed and not an issue) I assume you've run a profiler and have seen that there's something going on with these two functions that is causing your performance issues...because NOBODY would EVER try to optimize their code before even checking to see if it was necessary. That would be stupid. If you're not passing the data around there is NO overhead associated with it. If you are passing the data around then what happens is contingent upon HOW you are passing it around and what, if any optimizations your compiler performs. It might remove the passing around bit if it's smart enough to know it's not necessary.
[toc] | [prev] | [next] | [standalone]
| From | sravanreddy001 <sravanreddy001@gmail.com> |
|---|---|
| Date | 2011-09-30 19:31 -0700 |
| Message-ID | <2700668.317.1317436313608.JavaMail.geo-discussion-forums@yqlb4> |
| In reply to | #10617 |
[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.
}
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?
If any one of you can help me with similar stuff, please drop a mail to sravanreddy001 @ gmail.com I wont bother you
[toc] | [prev] | [next] | [standalone]
| From | Richard Damon <news.x.richarddamon@xoxy.net> |
|---|---|
| Date | 2011-09-30 23:14 -0400 |
| Message-ID | <4E86859F.50005@xoxy.net> |
| In reply to | #10621 |
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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c++
csiph-web