473,407 Members | 2,326 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,407 software developers and data experts.

What is the largest array I can allocate??

I was able to allocate a single array having 2.6GB (ie. w/ 700200000
elements of type float) yet when I did a cpuinfo on my computer, it
showed a cache size of 256KB and 1GB of memory. What happened??? I
thought new returns a contiguous block of memory???

Jul 23 '05 #1
6 2960

<bl**********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
I was able to allocate a single array having 2.6GB (ie. w/ 700200000
elements of type float)
Note that type 'float' does not have the same size on
all implementations. The total memory for that
many type 'float' objects could easily be different
on another system.
yet when I did a cpuinfo on my computer, it
showed a cache size of 256KB and 1GB of memory. What happened???
I suspect your platform uses some sort of virtual memory
mechanism. Microsoft Windows perhaps?

I
thought new returns a contiguous block of memory???


It does. But the address range of that memory need not
correspond to your platform's underlying 'real' addresses.
Your system will provide each program a certain size 'address
space'. That's the range of addresses which your program will
'see' (also subject to more adjustments by your C runtime).

As far as your question "how much can I allocate?", the
answer to that depends entirely upon the capabilites of
your platform and your C implementation. From the perspective
of your C implementation, the limit is the maximum value
representable by the type 'size_t', declared by <stdlib.h>
(and a few other headers).

-Mike
Jul 23 '05 #2
bl**********@gmail.com wrote:
I was able to allocate a single array having 2.6GB (ie. w/ 700200000
elements of type float) yet when I did a cpuinfo on my computer, it
showed a cache size of 256KB and 1GB of memory. What happened??? I
thought new returns a contiguous block of memory???


How is what you obtained from 'cpuinfo' contradicting your knowledge
that 'new' returns a contiguous block? Please try to stay within C++
language terms while explaining that (if you can). IOW, how does the
fact that "it showed a cache size of ..." prove that 'new' returned
a block that is (or isn't) contiguous?

V
Jul 23 '05 #3
let me rephrase the question (given that I have a dell machine w/ xeon
processor running fedore core 3)
1. Is heap a region of RAM?
2. Why did my program run out of memory at precisely 2.6GB? I knew it
was 2.6GB because I kept playing w/ the array'size which was,
nevertheless, time-consuming. Any faster alternative?

Jul 23 '05 #4

<bl**********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
let me rephrase the question (given that I have a dell machine w/ xeon
processor running fedore core 3)
1. Is heap a region of RAM?
That is not specified by the standard. The implementation has to act as if
the memory allocated by new is contiguous, but how it accomplishes that is
not specified. The data could be stored mechanically by balls dropping into
buckets, as far as the standard is concerned. :-)
2. Why did my program run out of memory at precisely 2.6GB? I knew it
was 2.6GB because I kept playing w/ the array'size which was,
nevertheless, time-consuming.
We don't know. Perhaps that's what your operating system settings specify.
It's not a subject covered by the language specifications. Perhaps you
could ask in a newsgroup or forum dedicated to your operating system.
Any faster alternative?


To what? Testing?
I think what you want is to research "virtual memory", especially how it
relates to your specific operating system. From a C++ standpoint, it's
irrelevant.
-Howard

Jul 23 '05 #5
bl**********@gmail.com wrote:
let me rephrase the question (given that I have a dell machine w/ xeon
processor running fedore core 3)
The hardware on which you run your program is irrelevant in a language
newsgroup. If you think it's relevant, your question must be off-topic.
1. Is heap a region of RAM?
No. Yes. Maybe. How can this be answered? The former is a concept
related to a running program, the latter is hardware. C++ programs run
on a virtual machine where certain things are true by definition, like
that any block you get from 'new' is contiguous.
2. Why did my program run out of memory at precisely 2.6GB? I knew it
was 2.6GB because I kept playing w/ the array'size which was,
nevertheless, time-consuming. Any faster alternative?


You should ask in a newsgroup related to your OS/platform. I'm afraid
those questions cannot be answered in terms of C++ language. In C++
it is enough to allocate and deallocate arrays of some sizes narrowing
down the maximum size that can be allocated, but on many platforms the
memory when 'delete'd is not immediately returned to the process thus
making a simple binary search for the maximum impossible.

V
Jul 23 '05 #6
bl**********@gmail.com schrieb:
let me rephrase the question (given that I have a dell machine w/ xeon
processor running fedore core 3)
1. Is heap a region of RAM?
No and yes. Heap is a region of "virtual memory". The virtual memory is
managed by the operation system (OS), like Linux, Windows etc.

Every program gets it's own virtual adress space from the OS.

If a program requests more memory than the amount of available RAM, the
OS swaps parts of the RAM to harddisk ("swapping"). This process
is completly transparent to the application.
2. Why did my program run out of memory at precisely 2.6GB? I knew it
was 2.6GB because I kept playing w/ the array'size which was,
nevertheless, time-consuming. Any faster alternative?


Using a large File and programming your own data cache management
could be faster than letting the OS do the "swap-game". But this
is a little more complex than using an array.

Best regards
Jul 23 '05 #7

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

Similar topics

4
by: Isaac | last post by:
Hi mates I want to know a simple program of return array from function ? Do I need to use pointer to return the address of the first element in an array. Isaac
22
by: Wynand Winterbach | last post by:
I think every C programmer can relate to the frustrations that malloc allocated arrays bring. In particular, I've always found the fact that the size of an array must be stored separately to be a...
20
by: Rajesh | last post by:
Hello Everybody, Can anybody help me to write a C program for finding the second largest element in an array. without using any sort algo. The array may conatin duplicate elements. The algo...
4
by: codergem | last post by:
Helo friends Could any of you please help me out with this problem. To me this program of heap sort seems logically perfect but still the output of this is not coming right, I dont want to follow...
19
by: ramu | last post by:
Hi, I have, suppose 1000 numbers, in a file. I have to find out 5 largest numbers among them without sorting. Can you please give me an efficient idea to do this? My idea is to put those numbers...
3
by: HEMH6 | last post by:
Who can help solve this problem??? Finding the Largest Value (a) write a function, largest(), that returns the largest value in a signed integer array. The array and its size are passed as...
3
by: Frank Rizzo | last post by:
It is common knowledge that 32-bit processes can use up to 2GB of RAM. This has been my experience with native (vb6, c++) apps. However, .NET apps tend to crash with Out of Memory errors whenever...
1
by: Peterwkc | last post by:
Hello all expert, i have two program which make me desperate bu after i have noticed the forum, my future is become brightness back. By the way, my problem is like this i the first program was...
38
by: bele_harshad2006 | last post by:
how can i pick up largest no from 5 rows by 5 column matrix????
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.