The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM



Thread: Heap and stack
View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #6 (permalink)  
Old 04-29-2008
andryk's Avatar
andryk andryk is offline
Registered User
 

Join Date: Sep 2003
Posts: 448
Quote:
Originally Posted by jim mcnamara View Post
Code:
main()
{
int *a;
.
.
}
a, itself, is on the stack. What part of memory a "is aimed at" is indeterminate in your code. It could be anywhere. Show us something like a=&some_int and then we can tell you. As it is there is no way to answer.

Next problem - gets works on string pointers, not int *
So I have no idea where gets would be working.

If you are worried about heap being "slower" than stack, don't. Unless you can definitely show that a gets call is a bottleneck - by using a profiler - it is a waste of programmer time to fuss over stuff like that.

gets works against the actual memory referenced by the pointer, it has nothing to do with where the pointer itself lives.

Andryk - void main () is a BAD idea, especially in a UNIX forum.
LOL, okay sorry for that, i was just 'quick-coding' to show the diff between vars allocated on stack and on heap ...
Reply With Quote