Sponsored Content
Full Discussion: find size of heap allocated
Top Forums Programming find size of heap allocated Post 302519795 by rupeshkp728 on Thursday 5th of May 2011 05:07:59 AM
Old 05-05-2011
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[1000];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 heap allocated in windbg it shows me the size as fc4 i.e. 4036 which is more then 4000 and not as desired. Any hint as to what may be the cause?

Last edited by rupeshkp728; 05-05-2011 at 07:42 AM..
 

10 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. UNIX for Advanced & Expert Users

monitor jvm heap size

I'm running websphere 4.5 on AIX 5 with java 1.3 and would like to find out the following: How much memory is allocated to each JVM, and how much of the allocated heap size is actually being used by a specific JVM? (0 Replies)
Discussion started by: rein
0 Replies

4. Solaris

command to find out total size of a specific file size (spread over the server)

hi all, in my server there are some specific application files which are spread through out the server... these are spread in folders..sub-folders..chid folders... please help me, how can i find the total size of these specific files in the server... (3 Replies)
Discussion started by: abhinov
3 Replies

5. Shell Programming and Scripting

script to gather weblogic jvm heap size stats

Hello, has anyone written something that will monitor/gather weblogic heap info ? I need to gather size, high/low stats to a file that I can upload to a speadsheet thanks for your help! (2 Replies)
Discussion started by: galenw
2 Replies

6. Shell Programming and Scripting

Finding Heap size Command--Urgent

Hi Friends, i need a unix command to check the heap space availability on unix system as I am getting following error: Error occurred during initialization of VM Could not reserve enough space for object heap Error occurred during initialization of VM Could not reserve enough space for... (2 Replies)
Discussion started by: Anji
2 Replies

7. HP-UX

how to find size of memory allocated to a pointer?

Hi, Am new to HP UX , is there a way to find out the size of memory allocated to a pointer on hp ux? For example we can use the _msize() on windows to find the size of memory allocated to a pointer . #include <stdio.h> #include <malloc.h> void main() { void *buffer; ... (0 Replies)
Discussion started by: Wkdunreal
0 Replies

8. UNIX for Dummies Questions & Answers

Checking heap memory size for java app

Hi I have one Java application installed in my Solaris system. Is there a way to find out the heap memory allocated size/used size/free size for the particular Java process? If anyone knows the command, please let me know. Even I appreciate if I have any scripts to find out the same. ... (0 Replies)
Discussion started by: nthiruvenkatam
0 Replies

9. UNIX for Dummies Questions & Answers

How to find the disk space allocated.

Hello, I need to find the total allocated disk space for the home directory. How can i find that in unix?(in GB). Thanks. (4 Replies)
Discussion started by: kailash19
4 Replies

10. Solaris

/tmp size is less whereas size allocated to swap is more

Hi, the /tmp size is less whereas the size allocated to swap is quite big. how to increase the size of /tmp - #: swap -l swapfile dev swaplo blocks free /dev/md/dsk/d20 85,20 8 273096 273096 #: swap -s total: 46875128k bytes allocated + 2347188k reserved =... (2 Replies)
Discussion started by: psb74
2 Replies
MEMUSAGE(1)							 Linux user manual						       MEMUSAGE(1)

NAME
memusage - profile memory usage of a program SYNOPSIS
memusage [option]... program [programoption]... DESCRIPTION
memusage is a bash script which profiles memory usage of the program, program. It preloads the libmemusage.so library into the caller's environment (via the LD_PRELOAD environment variable; see ld.so(8)). The libmemusage.so library traces memory allocation by intercepting calls to malloc(3), calloc(3), free(3), and realloc(3); optionally, calls to mmap(2), mremap(2), and munmap(2) can also be intercepted. memusage can output the collected data in textual form, or it can use memusagestat(1) (see the -p option, below) to create a PNG file con- taining graphical representation of the collected data. Memory usage summary The "Memory usage summary" line output by memusage contains three fields: heap total Sum of size arguments of all malloc(3) calls, products of arguments (nmemb*size) of all calloc(3) calls, and sum of length argu- ments of all mmap(2) calls. In the case of realloc(3) and mremap(2), if the new size of an allocation is larger than the previ- ous size, the sum of all such differences (new size minus old size) is added. heap peak Maximum of all size arguments of malloc(3), all products of nmemb*size of calloc(3), all size arguments of realloc(3), length arguments of mmap(2), and new_size arguments of mremap(2). stack peak Before the first call to any monitored function, the stack pointer address (base stack pointer) is saved. After each function call, the actual stack pointer address is read and the difference from the base stack pointer computed. The maximum of these differences is then the stack peak. Immediately following this summary line, a table shows the number calls, total memory allocated or deallocated, and number of failed calls for each intercepted function. For realloc(3) and mremap(2), the additional field "nomove" shows reallocations that changed the address of a block, and the additional "dec" field shows reallocations that decreased the size of the block. For realloc(3), the additional field "free" shows reallocations that caused a block to be freed (i.e., the reallocated size was 0). The "realloc/total memory" of the table output by memusage does not reflect cases where realloc(3) is used to reallocate a block of memory to have a smaller size than previously. This can cause sum of all "total memory" cells (excluding "free") to be larger than the "free/total memory" cell. Histogram for block sizes The "Histogram for block sizes" provides a breakdown of memory allocations into various bucket sizes. OPTIONS
-n name, --progname=name Name of the program file to profile. -p file, --png=file Generate PNG graphic and store it in file. -d file, --data=file Generate binary data file and store it in file. -u, --unbuffered Do not buffer output. -b size, --buffer=size Collect size entries before writing them out. --no-timer Disable timer-based (SIGPROF) sampling of stack pointer value. -m, --mmap Also trace mmap(2), mremap(2), and munmap(2). -?, --help Print help and exit. --usage Print a short usage message and exit. -V, --version Print version information and exit. The following options apply only when generating graphical output: -t, --time-based Use time (rather than number of function calls) as the scale for the X axis. -T, --total Also draw a graph of total memory use. --title=name Use name as the title of the graph. -x size, --x-size=size Make the graph size pixels wide. -y size, --y-size=size Make the graph size pixels high. EXIT STATUS
Exit status is equal to the exit status of profiled program. EXAMPLE
Below is a simple program that reallocates a block of memory in cycles that rise to a peak before then cyclically reallocating the memory in smaller blocks that return to zero. After compiling the program and running the following commands, a graph of the memory usage of the program can be found in the file memusage.png: $ memusage --data=memusage.dat ./a.out ... Memory usage summary: heap total: 45200, heap peak: 6440, stack peak: 224 total calls total memory failed calls malloc| 1 400 0 realloc| 40 44800 0 (nomove:40, dec:19, free:0) calloc| 0 0 0 free| 1 440 Histogram for block sizes: 192-207 1 2% ================ ... 2192-2207 1 2% ================ 2240-2255 2 4% ================================= 2832-2847 2 4% ================================= 3440-3455 2 4% ================================= 4032-4047 2 4% ================================= 4640-4655 2 4% ================================= 5232-5247 2 4% ================================= 5840-5855 2 4% ================================= 6432-6447 1 2% ================ $ memusagestat memusage.dat memusage.png Program source #include <stdio.h> #include <stdlib.h> #define CYCLES 20 int main(int argc, char *argv[]) { int i, j; int *p; printf("malloc: %zd ", sizeof(int) * 100); p = malloc(sizeof(int) * 100); for (i = 0; i < CYCLES; i++) { if (i < CYCLES / 2) j = i; else j--; printf("realloc: %zd ", sizeof(int) * (j * 50 + 110)); p = realloc(p, sizeof(int) * (j * 50 + 100)); printf("realloc: %zd ", sizeof(int) * ((j+1) * 150 + 110)); p = realloc(p, sizeof(int) * ((j + 1) * 150 + 110)); } free(p); exit(EXIT_SUCCESS); } BUGS
To report bugs, see <http://www.gnu.org/software/libc/bugs.html> SEE ALSO
memusagestat(1), mtrace(1) ld.so(8) GNU
2014-09-06 MEMUSAGE(1)
All times are GMT -4. The time now is 09:47 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy