Hi All,

Guess puneet wanted the mail to reach the whole group. SO I am forwarding.

And Puneet, please try and follow bottom posting. It does help a lot.


-------- Original Message --------
Subject: [Fwd: Re: (PT) Help on Heap & Stack]
Date: Thu, 02 Dec 2004 03:01:35 -0000
From: puneet_cs_in <[EMAIL PROTECTED]>
To: Kapil Sethi <[EMAIL PROTECTED]>


hi



Traditionally in a process address space you would see stack growing
upside down and heap growing upwards. An application wise difference
is all the memory allocated dynamically gets allocated on heap viz.
malloc free, calloc etc. The stack of an process contains stack frames
( containing the return address linkage for a function and the data
required in a stack which has the qualifier 'auto').

Efficiency-wise, one thing I can think of is memory on stack should
be a bit faster to access as the hit-ratio for the pages having stack
memory should have a better chances in terms of cache and also
virtual memory. There should be a few more here, which can be same as
choice of using array vs new().

The stack is basically a queue which gets (over-)written a lot. It is
really intended for function parameters and return codes. Better yet,
I would even suggest not having any parameters in functions which are
big (for instance a struct or a class).

Class CMyClass
{
int32 pi32Array[100000];
...
};

I would suggest using MyFunc(const CMyClass *pMyClassObj), which
takes only n-bit on the stack (on a n-bit machine, e.g. 32-bit),
instead of at least 100000 bytes (in this case).


Also, there is no save way to protect the stack space from being
overwritten (other than adjusting the ESP register yourself).

In conclusion, unless you're coding in assembly, don't use the stack
for general data.


Kapil
-- 
PS: I suggest the groupmembers to avoid top posting, as this pushes the 
original question to the bottom. While any body whould prefer to have 
the main question at the top, and subsequent replies added to the 
bottom, so that it is easy to comprehend the flow of information. So 
please stick to bottom posting.







------------------------ Yahoo! Groups Sponsor --------------------~--> 
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/EbFolB/TM
--------------------------------------------------------------------~-> 

To unsubscribe : [EMAIL PROTECTED]

 
Yahoo! Groups Links

<*> To reply to this message, go to:
    
http://groups.yahoo.com/group/Programmers-Town/post?act=reply&messageNum=4152
    Please do not reply to this message via email. More information here:
    http://help.yahoo.com/help/us/groups/messages/messages-23.html

<*> To visit your group on the web, go to:  
    http://groups.yahoo.com/group/Programmers-Town/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to