473,908 Members | 4,008 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Stacks and heaps

I've searched Google and found a few, but I am not so satisfied. Any
good reading on "stacks and heaps" about how and when memory is
allocated from the heap?
Nov 14 '05 #1
6 1686
On 2 Jun 2004 21:14:19 -0700, Vi************* ***@yahoo.com (Sathyaish)
wrote in comp.lang.c:
I've searched Google and found a few, but I am not so satisfied. Any
good reading on "stacks and heaps" about how and when memory is
allocated from the heap?


The C standard does not specify mechanisms like stacks and heaps.
Memory has three types of storage duration in C programs, static,
automatic, and dynamic.

When, how, and why an implementation provides and manages these types
of memory is up to the implementation. So if you are interested in
how a specific compiler manages memory, you need to ask in a compiler
specific support group.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 14 '05 #2
In <gu************ *************** *****@4ax.com> Jack Klein <ja*******@spam cop.net> writes:
On 2 Jun 2004 21:14:19 -0700, Vi************* ***@yahoo.com (Sathyaish)
wrote in comp.lang.c:
I've searched Google and found a few, but I am not so satisfied. Any
good reading on "stacks and heaps" about how and when memory is
allocated from the heap?
The C standard does not specify mechanisms like stacks and heaps.


These are data structures, not mechanisms.
Memory has three types of storage duration in C programs, static,
automatic, and dynamic.

When, how, and why an implementation provides and manages these types
of memory is up to the implementation. So if you are interested in
how a specific compiler manages memory, you need to ask in a compiler
specific support group.


There is nothing compiler specific in understanding how these data
structures can be used to implement automatic and dynamic memory
allocation.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #3
Sathyaish wrote:
I've searched Google and found a few, but I am not so satisfied. Any
good reading on "stacks and heaps" about how and when memory is
allocated from the heap?


Often times, compilers use a heap for managing dynamic memory.
Dynamic memory is memory that is set aside for the program to
use during run-time.

Most of the time, programs use the *alloc() family of functions
to allocate from dynamic memory. The memory stays allocated until
either the program deallocates the memory via free or the
program is terminated (and the memory is re-used by the operating
system).

Dynamic memory often is used when the amount cannot be determined
during compile time, or when the program needs more memory than
the compiler can allocate during compile time (or program load
time).

Linked lists are a classic example of using dynamic memory
allocation.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.l earn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

Nov 14 '05 #4
Thanks, Thomas and others. I want some more rigorous reading on this.
For instance, I could easily understand what Thomas Matthews said
because I knew it earlier plus I have some background of C and C++.
Where can I get more copious information on the internal working of
the heap?

PS: Thomas, haven't I seen you on JoS?
Nov 14 '05 #5
Sathyaish wrote:
Thanks, Thomas and others. I want some more rigorous reading on this.
For instance, I could easily understand what Thomas Matthews said
because I knew it earlier plus I have some background of C and C++.
Where can I get more copious information on the internal working of
the heap?
The heap is a tool (data structure) used by some compiler vendors to
manage dynamic memory. An implementation is not required to have
a heap in order to be compliant with the standard.

The question now is whether you want copious information about:
1. Heap data structures
2. Memory allocation methods (schemes)
3. Compiler Theory.
I suggest using your favorite web search engine with the appropriate
keywords and see what you can find. I took and older route and took
classes in the above at the University. Many Universities give the
Computer Science people a Compiler to write as their final project.

As far as the C language goes, you can do three things with
dynamic memory:
1. Allocate from it.
2. Reallocate from it.
2. Deallocate objects to it (i.e. return or free already
allocated items).
Kind of simple and boring. You allocate memory as you need it
and dispose of the objects when you are finished with them.
Anything beyond this, such as alignment and memory collection,
is beyond the scope of this newsgroup.


PS: Thomas, haven't I seen you on JoS?

What is JoS?
I remember playing with an operating system called JOSS, but
that was a long time ago.

If you know me, you might remember that I really hate acroynyms.
Just as a picture is worth a thousand words, one never really
knows which of those thousand words the author/artist was meaning
to convey. I prefer to be explicit. So, WTF is JoS?
--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.l earn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

Nov 14 '05 #6
That answers it. The Joel On Software site, a wonderful site about
software development issues, is more fondly known by its members as
JoS. Thanks for the info. I wish I'd gone to a university for a
Computer Science degree when my parents couldn't afford to send me.

Regards,
Sathyaish Chakravarthy.

Thomas Matthews <Th************ *************** *@sbcglobal.net > wrote in message news:<fM******* ******@newssvr1 6.news.prodigy. com>...
Sathyaish wrote:
Thanks, Thomas and others. I want some more rigorous reading on this.
For instance, I could easily understand what Thomas Matthews said
because I knew it earlier plus I have some background of C and C++.
Where can I get more copious information on the internal working of
the heap?


The heap is a tool (data structure) used by some compiler vendors to
manage dynamic memory. An implementation is not required to have
a heap in order to be compliant with the standard.

The question now is whether you want copious information about:
1. Heap data structures
2. Memory allocation methods (schemes)
3. Compiler Theory.
I suggest using your favorite web search engine with the appropriate
keywords and see what you can find. I took and older route and took
classes in the above at the University. Many Universities give the
Computer Science people a Compiler to write as their final project.

As far as the C language goes, you can do three things with
dynamic memory:
1. Allocate from it.
2. Reallocate from it.
2. Deallocate objects to it (i.e. return or free already
allocated items).
Kind of simple and boring. You allocate memory as you need it
and dispose of the objects when you are finished with them.
Anything beyond this, such as alignment and memory collection,
is beyond the scope of this newsgroup.


PS: Thomas, haven't I seen you on JoS?

What is JoS?
I remember playing with an operating system called JOSS, but
that was a long time ago.

If you know me, you might remember that I really hate acroynyms.
Just as a picture is worth a thousand words, one never really
knows which of those thousand words the author/artist was meaning
to convey. I prefer to be explicit. So, WTF is JoS?
--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.l earn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

Nov 14 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2625
by: Vanessa T. | last post by:
Hello All! Is there a place where I can learn stacks, (push and pop) etc. Thanks,
4
3210
by: Ice | last post by:
Hi there, I'm not sure if this is the right group for this- If it isn't, could anyone point me in the right direction? For our data structures exam, we are usually asked to implement the structures we've studied (ofcourse in c++). For e.g. implementations of a stack could be paranthesis matching/evaluating polish notation etc. Can anyone suggest implementations/usage of the above mentioned data
18
1592
by: pmm | last post by:
Hi all, Plz dont fire at me if this is a silly question Is there any way to know in which direction stack grows pmm
10
2152
by: Rich Kucera | last post by:
Holding all versions at 5.0.4, Multiple stacks with multiple-version configurations inevitable Will have to wait to see what the impact of problems such as http://bugs.php.net/bug.php?id=33643 to the application world. We may wait for a suitable popular resolution and jump to that version in the future. There's already a rift between PHP4 and PHP5, and then further developments such as these create another, splitting the camp into 4....
2
4590
by: Daniel | last post by:
Hi, I have a question regarding the memory managment in stl stacks. I want to use stacks to store a very large amount of numbers (some millions), thus I'm interested in how the stack behaves when it has to increase its memory. http://www.sgi.com/tech/stl/stack.html, the stacks default underlying container is a deque that has amortized constant time insertion and removal of elements.
0
2350
by: raghuveer | last post by:
i want to implement multiple stacks using arrays..I am able to create ,insert and print them but not poping an element form any of the stack..This is what i have #include<stdio.h> #include<conio.h> int top; int bot; void main() {
2
3494
by: John Grandy | last post by:
Are Gen 0, Gen 1, Gen 2 heaps and Large Object Heaps physically contiguous ? Or are these abstract representations of groups of allocated segments in the general heap ? More specifically, are the segments physically contiguous within each heap ? And are the heaps physically contiguous ? So, G1,G2,G3 heap max size, etc. (and LOH max size) are proportionate to the # of general heap memory segments currently allocated for each of these GC...
8
3945
by: cerise | last post by:
I can't figure out how to make and handle multiple stacks and use them so I could create four linked list stacks representing each suit of cards, one stack each for diamonds, hearts, spades, and clubs. I use objects as my cards. I don't know how to make more than one stack. Can anyone help me out? If I'm not being clear, I'll be happy to clarify the problem I have. here is the class I used to make the Objects for cards, public class...
3
1267
by: abhishek | last post by:
Hi group any idea on HOW TO HANDLE POINTERS FROM NON-LOCAL HEAPS?? Thank you
0
10029
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9875
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11335
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10536
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8094
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5930
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6133
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4765
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3354
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.