LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-04-2004, 09:06 AM   #1
thrifteed
LQ Newbie
 
Registered: Sep 2004
Posts: 4

Rep: Reputation: 0
array size/C++ memory limits for user space programs?


hi all,

i have a c++ memory issue that i need a little help with. i run a debian linux box (woody) using g++ 2.95.4.

i have created a custom class "myClass" which does something like this in one of it's methods:

SomeType myArray[aSize];

SomeType is also a custom class, but could be any other datatype such as int or double. "aSize" is determined during runtime.

the problem occurs for large values of "aSize", which leads me to believe that i'm reaching the process' memory limits, and that it is then killed by the OS. i have 2 reasons for this guess:

1. GDB points me to the line where i allocate the array, when the program does crash.
2. i have written 2 testprograms, both of which use "myClass", both of which work on the same data - the difference is, that one is a console-only app, the other has visual output (using QT/openGL). the console app is quite happy with values of "aSize" which may already crash the QT app... though it will also die, if "aSize" is sufficiantly large.

the thing is this: my machine has enough RAM to handle this array - swap isn't even touched! ulimit also says that i have no limits in resources:

uliimit -a gives:

core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
file size (blocks, -f) unlimited
max locked memory (kbytes, -l) unlimited
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 256
virtual memory (kbytes, -v) unlimited

any ideas, anyone?

thanks,

matthias
 
Old 09-04-2004, 09:44 AM   #2
wapcaplet
LQ Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
I'm no expert on memory management, but when you allocate an array in that fashion, you are asking for contiguous memory - that is, all of it has to be in one chunk. You may still have tons of RAM free, but the barrier you are hitting is when you don't have that much contiguous memory available.

If you're needing really large amounts of memory, a more dynamic allocation method might be better - a linked list perhaps? That way, the memory doesn't need to be contiguous.
 
Old 09-04-2004, 11:39 AM   #3
thrifteed
LQ Newbie
 
Registered: Sep 2004
Posts: 4

Original Poster
Rep: Reputation: 0
> You may still have tons of RAM free, but the barrier
> you are hitting is when you don't have that much
> contiguous memory available.

hi wapcaplet,

my thoughts the same... i'm not sure if i can change this,
though, because some of the algorithms i use in my
program require that the data be stored in this way... at least
i can't think of doing it differently right now.

thanks for your help!

matthias
 
Old 09-04-2004, 11:52 AM   #4
bruce ford
Member
 
Registered: Jul 2004
Location: Munich, Germany
Distribution: Sun Solaris 8, SuSE 9.0
Posts: 43

Rep: Reputation: 15
Hi,

Quote:
my thoughts the same... i'm not sure if i can change this, though, because some of the algorithms i use in my program require that the data be stored in this way...
do they really rely on an array or just on the access via operator[ ]?
If so you might be able to use an STL Vector instead.

so long...
bruce
 
Old 09-05-2004, 04:42 AM   #5
thrifteed
LQ Newbie
 
Registered: Sep 2004
Posts: 4

Original Poster
Rep: Reputation: 0
hi bruce,

that worked, thanks.

matthias
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
partition size limits pedromdsantos Linux - General 7 07-01-2005 03:56 PM
Samba User Home Drive Size Limits sunnyee Linux - Networking 3 07-13-2004 06:57 PM
HD size limits under slackware horndude Slackware 6 02-10-2004 07:34 PM
on modules and user-space programs h/w Programming 2 01-06-2004 03:42 PM
File Size limits ascii2k Linux - General 4 04-15-2002 10:25 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:19 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration