array size/C++ memory limits for user space programs?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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.
> 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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.