I haven't encoded after a while, so excuse me in advance. I have this weird problem. I am trying malloc 8GB at a time, and I plan to manage this bunch later with TLSF. That is, I want to avoid mallocing in my entire application at all, just get one big globe at the beginning and free it at the end. Here is the feature. I have always used dlmalloc so far in my programs. Binding him and everything went well. However, now that I try to malloc 8GB right away and link in dlmalloc to use it, I get segmentation fault 11 on OSX when I run it, without dlmalloc everything is going fine. It doesn't matter if I use gcc or clang. The system does not have 8 GB of RAM, although it has 4 GB. Interestingly, the same thing happens on a Windows machine that has 32 GB of RAM and Ubuntu with 16 GB of RAM. Everything works with the malloc system, the distribution passes, and a simple iteration through the allocated memory works, as expected, on all three systems. But, when I refer to dlmalloc, it fails. Tried this with both malloc function calls and dlmalloc.
The distribution itself is not unusual, simple c99.
[...] size_t bytes = 1024LL*1024LL*1024LL*8LL; unsigned long *m = (unsigned long*)malloc(bytes); [...]
I am confused by several things. Why does the malloc system give me 8 GB of memory, even without a system with 4 GB or RAM, are these virtual pages? Why doesn't dlmalloc do the same? I know that there cannot be a continuity block of 8 GB of RAM to allocate, but why a segmented error then why not zero ptr?
Is there a viable reliable (hopefully neutral for the platform) solution to get this amount of RAM at a time from malloc, even if I'm not sure that the system will have so much RAM?
edit: the program is 64-bit, like OS ', on which I am running.
edit2: So I played with him a little more. It turns out that if I break the distribution into 1 GB pieces, that is, 8 separate mallocs, then it works with dlmalloc. So this is a problem with continuous range allocation, where dlmalloc is probably trying to allocate only if there is a continuous block. This makes my question even more difficult to formulate. Is there any surefire way to get the size of the memory block with or without dlmalloc on all platforms, and not have it if there is no physical memory to the left (maybe in swap if it does not break). It would also be possible for the cross-platform way to determine if malloc is in ram or swap.