473,883 Members | 1,679 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 2987

<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
158002
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
2474
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
5123
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
2111
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
8602
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
3955
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
5366
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
7984
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
2479
by: bele_harshad2006 | last post by:
how can i pick up largest no from 5 rows by 5 column matrix????
0
9938
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
11140
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10742
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
10414
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
7125
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
5797
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
5991
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4611
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
3232
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.