473,769 Members | 4,173 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2979

<bl**********@g mail.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.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**********@gm ail.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**********@g mail.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.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**********@gm ail.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**********@gm ail.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
157996
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
2465
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 nightmare. There are of course many solutions, but they all end up forcing you to abandon the array syntax in favour of macros or functions. Now I have two questions - one is historical, and the other practical. 1.) Surely malloc (and...
20
5102
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 should run in O(n) time. Rajesh
4
2103
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 any other solution.Could any of you please take out some precious time of yours in solving this big problem for me, where m i going wrong??? Thanks in advance.
19
8591
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 into a binary tree and to find the largest numbers. How else can we do it? Regards
3
3952
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 arguments. (b)Write a main program that inputs MAX values from the keyboard into a signed integer array, array, and points, using largest(), the largest value to the screen.
3
5365
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 they approach 1.6 to 1.7 GB of RAM. Is the rest of the memory space between 1.7 GB and 2 GB is taken up by the runtime? 300mb? That cannot be since I've seen winform apps run (not fast, but still) on systems with 128mb. And if you set your...
1
7976
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 compiled and run without any erros but the second program has a run time error when the function return from allocate and the ptr become NULL. How to fixed this? Second Program: /* Best Method to allocate memory for 2D Array because it's ...
38
2458
by: bele_harshad2006 | last post by:
how can i pick up largest no from 5 rows by 5 column matrix????
0
9589
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
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10050
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...
0
9866
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6675
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
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3967
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
2
3570
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
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.