473,322 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

memory usage question

why does "int *iptr = new int[1024];" use up to 8KB of memory when i
only declared a ptr to 1024 integers? Intuitively, it should be only
1024*sizeof(int)+4 (for the pointer). Does C++ add an accompanying
pointer to every element or something? thanks.
Jul 19 '05 #1
4 3330
On 21 Jul 2003 16:05:08 -0700, la************@yahoo.com (Sean P.)
wrote:
why does "int *iptr = new int[1024];" use up to 8KB of memory when i
only declared a ptr to 1024 integers? Intuitively, it should be only
1024*sizeof(int)+4 (for the pointer). Does C++ add an accompanying
pointer to every element or something? thanks.


How did you determine the memory usage?

</dib>

John Dibling
email: dib@substitute_my_full_last_name_here.com
Witty banter omitted for your protection
Jul 19 '05 #2
Sean P. <la************@yahoo.com> wrote in message
news:cf**************************@posting.google.c om...
why does "int *iptr = new int[1024];" use up to 8KB of memory when i
only declared a ptr to 1024 integers? Intuitively, it should be only
1024*sizeof(int)+4 (for the pointer). Does C++ add an accompanying
pointer to every element or something? thanks.


How do you know that 8 kb has been used? What is sizeof(int) on your
machine?

Pedantic note: "Usage" means _how_ something is used, not how much.

DW

Jul 19 '05 #3

"Sean P." <la************@yahoo.com> wrote in message
news:cf**************************@posting.google.c om...
why does "int *iptr = new int[1024];" use up to 8KB of memory when i
only declared a ptr to 1024 integers? Intuitively, it should be only
1024*sizeof(int)+4 (for the pointer). Does C++ add an accompanying
pointer to every element or something? thanks.


There is always a small overhead when allocating memory. But there is no way
that on a system where sizeof(int) == 4 that allocating 1024 ints uses 8Kb.
More likely your method of finding out how much memory is being used is
faulty.

john
Jul 19 '05 #4
Sean P. wrote:
why does "int *iptr = new int[1024];" use up to 8KB of memory when i
only declared a ptr to 1024 integers? Intuitively, it should be only
1024*sizeof(int)+4 (for the pointer). Does C++ add an accompanying
pointer to every element or something? thanks.


Maybe your machine has a page size of 4kb, then
4*sizeof(int)+a_little_bit_overhead takes two pages.

Jul 19 '05 #5

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

Similar topics

6
by: Tom | last post by:
We have a VERY simple .NET C# Form Application, that has about a 23MB Memory Footprint. It starts a window runs a process and does a regular expression. I have done a GC.Collect to make sure that,...
3
by: Ian Taite | last post by:
Hello, I'm exploring why one of my C# .NET apps has "high" memory usage, and whether I can reduce the memory usage. I have an app that wakes up and processes text files into a database...
7
by: George Gre | last post by:
Hi, I wrote a c# programme that listens to incoming TCP requests and services them. This programme is meant to be running as long as the server its installed on is running. So we assume for...
4
by: Douglas | last post by:
Hi, Any suggestions for estimating the amount of memory a program will use in advance, before it is run. Rules of thumb etc.? Is it then possible to warn a user that a program is likely to...
5
by: SDS | last post by:
I am writing an ASP.NET application (in C#) that, as part of a particular response, populates a MemoryStream object with binary data that is being collected from a Process object's StandardOutput. ...
8
by: TheB | last post by:
Ok, lets try this again. I have a program which searches all disk drives for certain file types. When it finds a file it writes a record to a Firebird DB. The program normally is using 40 - 44...
7
by: Raj | last post by:
Hi Guys, We are on db2 udb v8.2 64 bit,partitioned (5 nodes) on AIX 5.2 ( intra parllelism is enabled). I have a question, i am trying to find the memory usage on my production machine, we...
11
by: Rares Vernica | last post by:
Hi, What is the right way/tool to find the peak memory usage of a C++ program? I tried Valgrind but is does not seem to be able to answer my question. Thanks a lot, Ray
3
by: crazy420fingers | last post by:
I'm running a python program that simulates a wireless network protocol for a certain number of "frames" (measure of time). I've observed the following: 1. The memory consumption of the program...
1
by: Jean-Paul Calderone | last post by:
On Tue, 22 Apr 2008 14:54:37 -0700 (PDT), yzghan@gmail.com wrote: The test doesn't demonstrate any leaks. It does demonstrate that memory usage can remain at or near peak memory usage even after...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.