Commit graph

8 commits

Author SHA1 Message Date
Leonardo de Moura
c5207489fd fix(memory): realloc must behave like malloc when ptr is nullptr
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-11-08 10:31:57 -08:00
Leonardo de Moura
c3c66b6c90 feat(make): add THREAD_SAFE build option
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-10-25 11:50:35 -07:00
Soonho Kong
a2a5a77a44 fix(memory): increase memory counters by the actual size of reallocated memory
On OSX, we had a test failure on memory module. The problem was in
the realloc function (line 38):

    void * realloc(void * ptr, size_t sz) {
        size_t old_sz = malloc_size(ptr);
        g_global_memory.dec(old_sz);
        g_global_memory.inc(sz);
        g_thread_memory.dec(old_sz);
        g_thread_memory.inc(sz);
        void * r = realloc_core(ptr, sz);
        if (r || sz == 0)
            return r;
        else
            ...

The size of r could be bigger than sz. For instance,

    |ptr| = 40 but |r| = 48

In the current code, here we only increase counters by 40.
But later when we free it, we decrease them by 48, and this
caused the problem, underflow of an unsigned counter in
g_global_memory.
2013-09-26 00:33:56 -07:00
Leonardo de Moura
d29ec9ab6f Add tests for memory.cpp
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-09-20 22:37:13 -07:00
Soonho Kong
bef44899c8 Suppress style warning on util/memory.cpp 2013-09-20 18:07:12 -07:00
Soonho Kong
9226c46358 Add support OSX's malloc_size 2013-09-20 17:48:55 -07:00
Leonardo de Moura
3971265bcb Add support for _msize
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-09-20 14:14:57 -07:00
Leonardo de Moura
dae654e4c6 Track memory usage. Add new CMake option TRACK_MEMORY_USAGE (It is ON by default).
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-09-20 12:32:12 -07:00