Please Help Me! How to use more 2GB (>7GB) in a C program
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.
Please Help Me! How to use more 2GB (>7GB) in a C program
I have an C program (GNU C) and i need it use more 2GB (7-8GB) of RAM, and i used malloc to allocate >2GB of RAM and i got crash (when running - not compiling)- "Segmentation fault". What does option of GNU C compiler support it?
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789
Rep:
Are you asking gcc to compile a 64 bit binary ?
Do you really want to use 7 GB of RAM, which is normally not a requirement for user space programs, but instead want to use 7 GB of virtual memory, and have the system mapping it to RAM when available ?
what do you get when you printf("%d\n", sizeof(size_t)) ?
(Since malloc() takes a size_t as its argument, it would be bad for you if it's 4 bytes..)
But it really does seem that you should be using mmap. I'm fairly certain I remember there being an mmap64 syscall, but I don't know if regular mmap calls that when you compile for 64bit or not.
what do you get when you printf("%d\n", sizeof(size_t)) ?
(Since malloc() takes a size_t as its argument, it would be bad for you if it's 4 bytes..)
But it really does seem that you should be using mmap. I'm fairly certain I remember there being an mmap64 syscall, but I don't know if regular mmap calls that when you compile for 64bit or not.
No, mmap64() only offers an off64_t: support for mapping any portion of a large file like you would do with mmap()
It's not easy to use portions of memory larger than SIZE_MAX, but the real limit is SSIZE_MAX. Both read() and write() say they accept size_t but they return ssize_t so there are implementations that don't support sizes between SSIZE_MAX and SIZE_MAX - 2, and in those that do, code such as "if (read(fd, buf, size) < 0)" will fail horribly because SSIZE_MAX + 1 becomes negative on a signed variable.
I think you'd have to code a library on top of mmap and I/O calls and you'd have to keep an array of addresses and their lengths associated to mmap() returned pointers. But first try to see if your OS supports many of these.
why don't u try increasing the amount of swap.
swap space can be created on a separate partition or by creating a file on an existing partition and mounting it as swap
to create a 1 MB swap file:
Code:
dd if=/dev/zero of=swapfile bs=1000000
mkswap swapfile (This cmd makes the file suitable for swap)
swapon swapfile (Turn on the swap usage)
Post your result
Last edited by Intimidator; 03-05-2006 at 02:12 PM.
One hacky way to get it to work is use mmap with 2gb segments and MAP_FIXED to line them up against eachother. As long as you start by finding an 8gb area of your address space that's free (shouldn't be hard with a 64bit space; use pmap if unsure), there's not much to pontificate about.
I think I can use "shared memory" to resolve my problem (because an application can get 2GB of RAM) and i will get the memory area's address to use in other application.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.