473,791 Members | 2,995 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I know size of avaible memory in heap?

How can I know size of avaible memory in heap?
For example :
....
....
// size = N
cout << "Size of Heap = " << SizeOfHeap() << endl;
int* i = new int;
// size = N - sizeof(int)
cout << "Size of Heap = " << SizeOfHeap() << endl;
....
....

SizeOfHeap() == ???

Jul 23 '05 #1
6 2653
If this function is OS/Compiler depend:
I use Linux RH 7.3 and gcc-4.0

Jul 23 '05 #2
On 20 Jun 2005 08:14:52 -0700, "Dima" <di**@inotech.r u> wrote:
How can I know size of avaible memory in heap?
For example :
...
...
// size = N
cout << "Size of Heap = " << SizeOfHeap() << endl;
int* i = new int;
// size = N - sizeof(int)
cout << "Size of Heap = " << SizeOfHeap() << endl;
...
...

SizeOfHeap() == ???


Two questions:

(1) What heap?
(2) What for??

The C++ language has no facilities for checking heap size; this is a
function of the operating system. Your question is therefore off-topic
in this newsgroup.

In general, the process heap will grow as needed. Unless you are doing
very low-level, close to the hardware things, you don't need (and
don't want) to know. If you need to allocate huge amounts of memory,
you will need to use OS-specific ways of allocating virtual memory.
Otherwise, just call new and delete and don't worry.

--
Bob Hairgrove
No**********@Ho me.com
Jul 23 '05 #3
On Mon, 20 Jun 2005 19:25:14 +0400, Dima <di**@inotech.r u> wrote:
If this function is OS/Compiler depend:
I use Linux RH 7.3 and gcc-4.0


Then just go open <malloc.h> and study the functions available to you.

--
Maxim Yegorushkin
Jul 23 '05 #4
Bob Hairgrove is clearly having a bad hair day.
Given that Dima didn't know the answer, how might he possibly know it
was mildly off topic ?
Altough Bob is pedantically correct that C++ doesn't specify how the
heap is managed the sort of problem that Dima is encountering proably
has a direct C++ solution.

I rather suspect that he is trying to write code that deal with low
memory situations.
In which case he might well benefit from learning about overloading new
for some sort of placement new implementation.

It's not just for when you are allocating huge amounts of memory. I
have seen several heap implementations get terribly fragmented and thus
get very slow. This can also lea to false reports of not enough memory.
If Dima is creating many objects of varying size, it is possible he
needs to understand this stuff.

DominiConnor
Quant Headhunter

Jul 23 '05 #5
"Dima" <di**@inotech.r u> wrote in message
news:11******** **************@ g47g2000cwa.goo glegroups.com.. .
How can I know size of avaible memory in heap?
For example :
...
...
// size = N
cout << "Size of Heap = " << SizeOfHeap() << endl;
int* i = new int;
// size = N - sizeof(int)
cout << "Size of Heap = " << SizeOfHeap() << endl;
...
...

SizeOfHeap() == ???


One solution to this problem I saw, but I didn't like, just
did malloc with huge amounts and determined when it
failed.

Basically you probably really want to determine if you have
enough heap to do something. If you think you'll need 10
megs of heap you could try allocating 10 megs of memory
in a malloc (remembering to release it if successful) and
check to see if it allowed it.

There is probably a better solution, but I believe it's OS
dependant.
Jul 23 '05 #6


do**********@gm ail.com wrote:
Bob Hairgrove is clearly having a bad hair day.
Given that Dima didn't know the answer, how might he possibly know it
was mildly off topic ?
It's an observation, not a judgement (in this case)
although I suspect Dima didn't read the FAQ.

I rather suspect that he is trying to write code that deal with low
memory situations.
In which case he might well benefit from learning about overloading new
for some sort of placement new implementation.


Regular placement new doesn't make a lot of sense in this
context. It doens't care about memory, heap or otherwise.
There are special forms, but those are rather exotic.
Usually you just need an replacement operator new (which
is not an overload either), or an operator new for a
single class.

HTH,
Michiel Salters

Jul 23 '05 #7

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

Similar topics

0
6816
by: Ravi Tallury | last post by:
Hi We are having issues with our application, certain portions of it stop responding while the rest of the application is fine. I am attaching the Java Core dump. If someone can let me know what the issue is. Thanks Ravi
1
40541
by: Oleg Konovalov | last post by:
Hi, I am running applets in Java Plug-in 1.4.2 under IE6 and often receive OutOfMemory exceptions (dealing with large file - video clips, etc.) although according to option M, almost 50% (out of 64MB) of memory is available. If I start playing with Java Runtime parameters, like setting it to mx128m, it actualy decreases the heap size:
7
2372
by: Bart Torbert | last post by:
Hello, I am starting to examine using SQLServer instead of Oracle. I went through the SQLServer import utility to copy tables from Oracle into SQLServer. I then checked the size of the database. I then started to specify indices for the tables. I did not see the database file size grow all that much. I kept on using the shrink command to make sure that wasted space was removed. I even made sure that minimal free space was allowed.
3
495
by: nvjoglekar | last post by:
Hi All My program needs a lot of memory and after allocating some using NEW statement, it returns NULL for any new object created. I guess that is becuase of the heap size limitation of the Visual Studio which stands at 1MB. I need to increase it. One option I found was to set /HEAP:memory in the Link options of project setting. Bur it didn't seem to work. I am getting same problem again. Dows anybody has a opinion about this.
9
3970
by: pvinodhkumar | last post by:
The number of elemets of the array, the array bound must be constant expression?Why is this restriction? Vinodh
11
17688
by: ganesh.kundapur | last post by:
Hi, Is there any way to get the total heap size allocated to a process in c on linux platform. Regards, Ganesh
11
5217
by: Andy Watson | last post by:
I have an application that scans and processes a bunch of text files. The content I'm pulling out and holding in memory is at least 200MB. I'd love to be able to tell the CPython virtual machine that I need a heap of, say 300MB up front rather than have it grow as needed. I've had a scan through the archives of comp.lang.python and the python docs but cannot find a way to do this. Is this possible to configure the PVM this way? ...
7
5637
by: Raman | last post by:
Hi All, Could any one tell me, how can I determine/Change size of heap on per- process basis on Unix based systems. Thanks. Regards
2
3026
by: shorti | last post by:
Hello, I am running DB2 V8.2 on AIX. I am looking for a way to get the memory size of a specific db2 agent. I have found the db2mtrk tool that gives me a list of all the applications and heap sizes. Also there is "DB2 Snapshot for Application" but I am looking for a way to capture the data for C code without having to parse through a file. The SNAPSHOT_APPL and SNAPSHOT_APPL_INFO table functions seem to fall short of the information ...
0
9669
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
10207
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10155
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7537
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
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5431
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
5559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4110
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
2916
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.