[gentoo-user] [OT] global variables and memory limitations
Folks, I am not certain if this has anything to do with Gentoo or not. I am programming something in C, and I need to address as much memory as possible for the arrays that need to be specified as global variables. I have 2 GB memory on this machine, and I'd like to use as much of it as possible, but my code segfaults if I try to allocate more than around 1 GB of RAM to my running code like that. I heard that this is due to the dynamic libraries. If I compile with gcc and use the static flag, I can allocate close to the physical limit (maybe 1.7 or 1.8 GB) and also if I allocate my variables dynamically, I can do the same thing. But the problem is, I cannot compile statically since I need the math libraries. I could go the route of dynamic allocation, but I need to invest significant efforts to restructure my code. I saw a thread on something similar to this on Beowulf, where they suggested moving the dynamic libraries somehow : changing the location of the shared libraries in memory by changing the variable __PAGE_OFFSET in kernel header files... How do I do that and do i need to recompile the kernel after attempting something like this? Thanks! Denis -- gentoo-user@gentoo.org mailing list
Re: [gentoo-user] [OT] global variables and memory limitations
Denis wrote: Folks, I am not certain if this has anything to do with Gentoo or not. I am programming something in C, and I need to address as much memory as possible for the arrays that need to be specified as global variables. I have 2 GB memory on this machine, and I'd like to use as much of it as possible, but my code segfaults if I try to allocate more than around 1 GB of RAM to my running code like that. I heard that this is due to the dynamic libraries. If I compile with gcc and use the Hi Denis, I know I'm not answering your question directly, but would *strongly* suggest going the dynamic route. The reason is that you are going to want to leave some memory spare for other processes and the kernel to use, or the first time you actually run out of memory, _your_ application is going to be killed by the kernel. It kills the largest memory user first, and it doesn't really matter whether that was stack space or heap space. Your best chance of avoiding the out-of-memory killer is to detect how much spare memory is available at application start, and then allocate 90-95% of that. That assumes of course that you have a high-degree of control over the system and that you don't have to worry about something started by a cron job wanting 200MB of memory. -Richard -- gentoo-user@gentoo.org mailing list