Sponsored Content
Full Discussion: Heap and stack
Top Forums Programming Heap and stack Post 302189868 by vino on Monday 28th of April 2008 05:43:27 AM
Old 04-28-2008
Quote:
Originally Posted by andryk
Hi,
It'll be on stack i suppose and in general all variables declared inside a function will be on stack as well.
Code:
unsigned long sp(void) {
   asm("movl %esp, %eax");
}
void main() {
  int *a;

  a=malloc(16*sizeof(int));
  printf ("addr of a is %p, sp is %p and malloc is %p\n",&a,sp(),a);
}

In the above case, a will point to the memory in the heap storage. Heap because of the malloc.

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;

 

8 More Discussions You Might Find Interesting

1. Filesystems, Disks and Memory

heap size!

I'm a new guy to this field and I'm learning a lot about UNIX! Can any explan to me what exactly does 'heap size' mean and how can i increase the size for AIX 4.3.3? (2 Replies)
Discussion started by: i2admin
2 Replies

2. Filesystems, Disks and Memory

heap size for JVM!

Hi all, Thanks 'thehoghunter' and 'hugo' for the comments! I've to increase the size of the heap size for AIX 4.3.3. Now what's the command that I've and also is it something similar to growing the file system in Solaris (growfs) (1 Reply)
Discussion started by: i2admin
1 Replies

3. AIX

AIX 5.3 Heap Memory with SAP

Any idea whether this parameter can be set / adjusted and where please? (3 Replies)
Discussion started by: johnf
3 Replies

4. Programming

what is stack winding and stack unwinding

helo can u tell me what do you mean by stack winding and stack unwinding Regards, Amit (2 Replies)
Discussion started by: amitpansuria
2 Replies

5. HP-UX

Heap fragementation on HPUX

The Resident size(as observed from top) of my process is increasing. But, the behaviour is very random. My process works on request reponse model. So when i put some request load on my process the memory starts increasing. For initial few hours (approx ~3 hrs) it increase at a rapid rate and after... (1 Reply)
Discussion started by: atgoel
1 Replies

6. HP-UX

Heap fragmentation on HPUX

Hi All, We are facing issues on HPUX with the C heap region growing. We use a product for CRM by name ClarifyCRM and it uses a native layer for DB access. so there are best practices in place to actual control memory. recently we have seen issues that the C heap region is growing faster than... (0 Replies)
Discussion started by: ramchand75
0 Replies

7. Programming

find size of heap allocated

I want to find the size of the total memory allocated on the heap for the following statement: int* a = new int;How can I use the sizeof operator for this? I used: printf("\t===> %d\n",sizeof(*a)); Is this statement correct? I have asked the question because when I checked the memory of... (13 Replies)
Discussion started by: rupeshkp728
13 Replies

8. UNIX for Dummies Questions & Answers

Kernel Stack vs User Mode Stack

Hi, I am new to the linux kernel development area. I want to know what is the difference between kernel mode stack and user mode stack? Does each process has a user mode stack and a kernel mode stack?? Or Each process has a user mode stack and there is only one kernel mode stack that is shared by... (4 Replies)
Discussion started by: saurabhkoar
4 Replies
Cache::File::Heap(3pm)					User Contributed Perl Documentation				    Cache::File::Heap(3pm)

NAME
Cache::File::Heap - A file based heap for use by Cache::File SYNOPSIS
use Cache::File::Heap; $heap = Cache::File::Heap->new('/path/to/some/heap/file'); $heap->add($key, $val); ($key, $val) = $heap->minimum; ($key, $val) = $heap->extract_minimum; $heap->delete($key, $val); DESCRIPTION
This module is a wrapper around a Berkeley DB using a btree structure to implement a heap. It is specifically for use by Cache::File for storing expiry times (although with a bit of work it could be made more general). See LIMITATIONS below. CONSTRUCTOR
my $heap = Cache::File::Heap->new( [$dbfile] ); The heap constructor takes an optional argument which is the name of the database file to open. If specified, it will attempt to open the database during construction. A new Cache::File::Heap blessed reference will be returned, or undef if the open failed. METHODS
$h->open($dbfile) Opens the specified database file. $h->close() Closes a previously opened heap database. Note that the database will be automatically closed when the heap reference is destroyed. $h->add($key, $val) Adds a key and value pair to the heap. Currently the key should be a number, whilst the value may be any scalar. Invokes 'die' on failure (use eval to catch it). $h->delete($key, $val) Removes a key and value pair from the heap. Returns 1 if the pair was found and removed, or 0 otherwise. ($key, $val) = $h->minimum() In list context, returns the smallest key and value pair from the heap. In scalar context only the key is returned. Note smallest is defined via a numerical comparison (hence keys should always be numbers). ($key, $vals) = $h->minimum_dup() In list context, returns the smallest key and an array reference containing all the values for that key from the heap. In scalar context only the key is returned. ($key, $val) = $h->extract_minimum() As for $h->minimum(), but the key and value pair is removed from the heap. ($key, $vals) = $h->extract_minimum_dup() As for $h->minimum_dup(), but all the values are removed from the heap. SEE ALSO
Cache::File AUTHOR
Chris Leishman <chris@leishman.org> Based on work by DeWitt Clinton <dewitt@unto.net> COPYRIGHT
Copyright (C) 2003-2006 Chris Leishman. All Rights Reserved. This module is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either expressed or implied. This program is free software; you can redistribute or modify it under the same terms as Perl itself. $Id: Heap.pm,v 1.6 2006/01/31 15:23:58 caleishm Exp $ perl v5.12.4 2011-08-05 Cache::File::Heap(3pm)
All times are GMT -4. The time now is 09:37 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy