Dynamically allocating multiple big arrays in C
up vote
0
down vote
favorite
I'm writing a program in C on windows that launches 30 threads, each of which needs an array of int16_t
.
The size is calculated before the thread function is called and in the example I'm working with it's around 250 millions. This is around 15GB, which should not be a problem, because I have 128GB ram available.
I've tried using both malloc
and calloc
inside the thread function, but over half of the allocations return NULL with errno
set to 12 (enomem
).
With a small number of threads (up to 3) it works fine though, same if I just use 1 thread and allocating an unreasonably big array.
My next attempt to solve this issue was to create an array of pointers in the main, allocate the arrays there and pass them as argument to the thread, same thing happened.
So from these results my best guess would be it can't allocate contiguous blocks of memory of that size, so I also tried allocating many smaller arrays, which obviously didn't work either. Is this an expected behaviour or am I doing something wrong?
c arrays windows malloc
|
show 4 more comments
up vote
0
down vote
favorite
I'm writing a program in C on windows that launches 30 threads, each of which needs an array of int16_t
.
The size is calculated before the thread function is called and in the example I'm working with it's around 250 millions. This is around 15GB, which should not be a problem, because I have 128GB ram available.
I've tried using both malloc
and calloc
inside the thread function, but over half of the allocations return NULL with errno
set to 12 (enomem
).
With a small number of threads (up to 3) it works fine though, same if I just use 1 thread and allocating an unreasonably big array.
My next attempt to solve this issue was to create an array of pointers in the main, allocate the arrays there and pass them as argument to the thread, same thing happened.
So from these results my best guess would be it can't allocate contiguous blocks of memory of that size, so I also tried allocating many smaller arrays, which obviously didn't work either. Is this an expected behaviour or am I doing something wrong?
c arrays windows malloc
2 * 250 * 10^6 * 30 = 15*10^9 bytes. Sanity check your spec before you start coding away maybe.
– Lundin
Nov 22 at 15:33
guess I should've mentioned I have 128 gb of ram available
– incantation
Nov 22 at 15:37
2
I guess what you are actually asking is this: stackoverflow.com/questions/11891593/…
– Lundin
Nov 22 at 15:42
Also a Minimal, Complete, and Verifiable example might help. Just the part that does the failing creation of the array of pointers inmain
.
– Jabberwocky
Nov 22 at 15:44
1
Are you compiling as 32 bit or 64 bit code? A 32 bit process cannot address more than 4 GB of memory, even if your computer has 128Gb or ram.
– Jabberwocky
Nov 22 at 15:48
|
show 4 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm writing a program in C on windows that launches 30 threads, each of which needs an array of int16_t
.
The size is calculated before the thread function is called and in the example I'm working with it's around 250 millions. This is around 15GB, which should not be a problem, because I have 128GB ram available.
I've tried using both malloc
and calloc
inside the thread function, but over half of the allocations return NULL with errno
set to 12 (enomem
).
With a small number of threads (up to 3) it works fine though, same if I just use 1 thread and allocating an unreasonably big array.
My next attempt to solve this issue was to create an array of pointers in the main, allocate the arrays there and pass them as argument to the thread, same thing happened.
So from these results my best guess would be it can't allocate contiguous blocks of memory of that size, so I also tried allocating many smaller arrays, which obviously didn't work either. Is this an expected behaviour or am I doing something wrong?
c arrays windows malloc
I'm writing a program in C on windows that launches 30 threads, each of which needs an array of int16_t
.
The size is calculated before the thread function is called and in the example I'm working with it's around 250 millions. This is around 15GB, which should not be a problem, because I have 128GB ram available.
I've tried using both malloc
and calloc
inside the thread function, but over half of the allocations return NULL with errno
set to 12 (enomem
).
With a small number of threads (up to 3) it works fine though, same if I just use 1 thread and allocating an unreasonably big array.
My next attempt to solve this issue was to create an array of pointers in the main, allocate the arrays there and pass them as argument to the thread, same thing happened.
So from these results my best guess would be it can't allocate contiguous blocks of memory of that size, so I also tried allocating many smaller arrays, which obviously didn't work either. Is this an expected behaviour or am I doing something wrong?
c arrays windows malloc
c arrays windows malloc
edited Nov 22 at 16:06
Ring Ø
21.3k45080
21.3k45080
asked Nov 22 at 15:29
incantation
83
83
2 * 250 * 10^6 * 30 = 15*10^9 bytes. Sanity check your spec before you start coding away maybe.
– Lundin
Nov 22 at 15:33
guess I should've mentioned I have 128 gb of ram available
– incantation
Nov 22 at 15:37
2
I guess what you are actually asking is this: stackoverflow.com/questions/11891593/…
– Lundin
Nov 22 at 15:42
Also a Minimal, Complete, and Verifiable example might help. Just the part that does the failing creation of the array of pointers inmain
.
– Jabberwocky
Nov 22 at 15:44
1
Are you compiling as 32 bit or 64 bit code? A 32 bit process cannot address more than 4 GB of memory, even if your computer has 128Gb or ram.
– Jabberwocky
Nov 22 at 15:48
|
show 4 more comments
2 * 250 * 10^6 * 30 = 15*10^9 bytes. Sanity check your spec before you start coding away maybe.
– Lundin
Nov 22 at 15:33
guess I should've mentioned I have 128 gb of ram available
– incantation
Nov 22 at 15:37
2
I guess what you are actually asking is this: stackoverflow.com/questions/11891593/…
– Lundin
Nov 22 at 15:42
Also a Minimal, Complete, and Verifiable example might help. Just the part that does the failing creation of the array of pointers inmain
.
– Jabberwocky
Nov 22 at 15:44
1
Are you compiling as 32 bit or 64 bit code? A 32 bit process cannot address more than 4 GB of memory, even if your computer has 128Gb or ram.
– Jabberwocky
Nov 22 at 15:48
2 * 250 * 10^6 * 30 = 15*10^9 bytes. Sanity check your spec before you start coding away maybe.
– Lundin
Nov 22 at 15:33
2 * 250 * 10^6 * 30 = 15*10^9 bytes. Sanity check your spec before you start coding away maybe.
– Lundin
Nov 22 at 15:33
guess I should've mentioned I have 128 gb of ram available
– incantation
Nov 22 at 15:37
guess I should've mentioned I have 128 gb of ram available
– incantation
Nov 22 at 15:37
2
2
I guess what you are actually asking is this: stackoverflow.com/questions/11891593/…
– Lundin
Nov 22 at 15:42
I guess what you are actually asking is this: stackoverflow.com/questions/11891593/…
– Lundin
Nov 22 at 15:42
Also a Minimal, Complete, and Verifiable example might help. Just the part that does the failing creation of the array of pointers in
main
.– Jabberwocky
Nov 22 at 15:44
Also a Minimal, Complete, and Verifiable example might help. Just the part that does the failing creation of the array of pointers in
main
.– Jabberwocky
Nov 22 at 15:44
1
1
Are you compiling as 32 bit or 64 bit code? A 32 bit process cannot address more than 4 GB of memory, even if your computer has 128Gb or ram.
– Jabberwocky
Nov 22 at 15:48
Are you compiling as 32 bit or 64 bit code? A 32 bit process cannot address more than 4 GB of memory, even if your computer has 128Gb or ram.
– Jabberwocky
Nov 22 at 15:48
|
show 4 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53434140%2fdynamically-allocating-multiple-big-arrays-in-c%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2 * 250 * 10^6 * 30 = 15*10^9 bytes. Sanity check your spec before you start coding away maybe.
– Lundin
Nov 22 at 15:33
guess I should've mentioned I have 128 gb of ram available
– incantation
Nov 22 at 15:37
2
I guess what you are actually asking is this: stackoverflow.com/questions/11891593/…
– Lundin
Nov 22 at 15:42
Also a Minimal, Complete, and Verifiable example might help. Just the part that does the failing creation of the array of pointers in
main
.– Jabberwocky
Nov 22 at 15:44
1
Are you compiling as 32 bit or 64 bit code? A 32 bit process cannot address more than 4 GB of memory, even if your computer has 128Gb or ram.
– Jabberwocky
Nov 22 at 15:48