![]() |
|
|
|
|
|||||||
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| what is stack winding and stack unwinding | amitpansuria | High Level Programming | 2 | 08-07-2007 02:46 PM |
| AIX 5.3 Heap Memory with SAP | johnf | AIX | 3 | 10-23-2006 02:21 AM |
| monitor jvm heap size | rein | UNIX for Advanced & Expert Users | 0 | 07-21-2005 05:29 AM |
| heap size for JVM! | i2admin | Filesystems, Disks and Memory | 1 | 05-09-2002 06:09 AM |
| heap size! | i2admin | Filesystems, Disks and Memory | 2 | 05-08-2002 07:20 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
Heap and stack
Hi,
I have a basic doubt here. Consider the following code snippet: main() { int *a; . . } Here the memory for a gets allocated in heap or stack. |
| Forum Sponsor | ||
|
|
|
||||
|
Quote:
On the other hand, in the following case, a will point to a memory location in the stack. Code:
int i = 10; int *a = &i; |
|
|||
|
Code:
main()
{
int *a;
.
.
}
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. |
|
|||
|
Memory for both heap and stack is allocated dynamically. The difference is that while stack memory is allocated automatically by the kernel whenever a function is called...heap memory is allocated only-on-request when the program calls malloc(). But as jim mcnamara has pointed out as a programmer you should not fuss over it.
|
|
||||
|
Quote:
|
||||
| Google UNIX.COM |
| Thread Tools | |
| Display Modes | |
|
|
|
The 50 most popular UNIX and Linux searches.
Google Search Cloud for The UNIX and Linux Forums
|
| 421 service not available, remote server has closed connection ^m automate ftp autosys awk trim bash eval bash exec bash for loop command copy/move folder in unix couldn't set locale correctly curses.h cut command in unix daemon process export command in unix find grep find mtime find null character in a unix file grep multiple lines grep or grep recursive hp-ux ifconfig inaddr_any inappropriate ioctl for device lynx javascript mailx attachment mget mtime ping port remove first character from string in k shell replace space by comma , perl script scp recursive segmentation fault(coredump) sftp script snoop unix stale nfs file handle syn_sent tar exclude tar extract to folder test: argument expected unix unix .profile unix forum unix forums unix interview questions unix simulator unix.com vi select all vi substitute vi+substitute+end+of+line+character while loop within while loop shell script |