Skip to content

Commit

Permalink
Remove DEBUG_MEMORY_NAME and xrMemory_subst_borland.*
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Jan 12, 2018
1 parent 842ba40 commit 508755e
Show file tree
Hide file tree
Showing 13 changed files with 9 additions and 156 deletions.
20 changes: 0 additions & 20 deletions src/Layers/xrRender/DetailManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,38 +96,18 @@ CDetailManager::CDetailManager() : xrc("detail manager")
dm_cache_size = dm_current_cache_size;
dm_fade = dm_current_fade;
ps_r__Detail_density = ps_current_detail_density;
#ifdef DEBUG_MEMORY_NAME
cache_level1 = (CacheSlot1**)Memory.mem_alloc(dm_cache1_line * sizeof(CacheSlot1*), "CDetailManager::cache_level1");
#else
cache_level1 = (CacheSlot1**)Memory.mem_alloc(dm_cache1_line * sizeof(CacheSlot1*));
#endif
for (u32 i = 0; i < dm_cache1_line; ++i)
{
#ifdef DEBUG_MEMORY_NAME
cache_level1[i] = (CacheSlot1*)Memory.mem_alloc(dm_cache1_line * sizeof(CacheSlot1), "CDetailManager::cache_level1 " + i);
#else
cache_level1[i] = (CacheSlot1*)Memory.mem_alloc(dm_cache1_line * sizeof(CacheSlot1));
#endif
for (u32 j = 0; j < dm_cache1_line; ++j)
new(&cache_level1[i][j]) CacheSlot1();
}
#ifdef DEBUG_MEMORY_NAME
cache = (Slot***)Memory.mem_alloc(dm_cache_line * sizeof(Slot**), "CDetailManager::cache");
#else
cache = (Slot***)Memory.mem_alloc(dm_cache_line * sizeof(Slot**));
#endif
for (u32 i = 0; i < dm_cache_line; ++i)
#ifdef DEBUG_MEMORY_NAME
cache[i] = (Slot**)Memory.mem_alloc(dm_cache_line * sizeof(Slot*), "CDetailManager::cache " + i);
#else
cache[i] = (Slot**)Memory.mem_alloc(dm_cache_line * sizeof(Slot*));
#endif

#ifdef DEBUG_MEMORY_NAME
cache_pool = (Slot *)Memory.mem_alloc(dm_cache_size * sizeof(Slot), "CDetailManager::cache_pool");
#else
cache_pool = (Slot *)Memory.mem_alloc(dm_cache_size * sizeof(Slot));
#endif

for (u32 i = 0; i < dm_cache_size; ++i)
new(&cache_pool[i]) Slot();
Expand Down
21 changes: 3 additions & 18 deletions src/xrCore/FS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,7 @@ bool file_handle_internal(LPCSTR file_name, u32& size, int& file_handle)

void* FileDownload(LPCSTR file_name, const int& file_handle, u32& file_size)
{
void* buffer = Memory.mem_alloc(file_size
#ifdef DEBUG_MEMORY_NAME
,
"FILE in memory"
#endif // DEBUG_MEMORY_NAME
);
void* buffer = Memory.mem_alloc(file_size);

int r_bytes = _read(file_handle, buffer, file_size);
R_ASSERT3(
Expand Down Expand Up @@ -204,19 +199,9 @@ void CMemoryWriter::w(const void* ptr, u32 count)
while (mem_size <= (position + count))
mem_size *= 2;
if (0 == data)
data = (BYTE*)Memory.mem_alloc(mem_size
#ifdef DEBUG_MEMORY_NAME
,
"CMemoryWriter - storage"
#endif // DEBUG_MEMORY_NAME
);
data = (BYTE*)Memory.mem_alloc(mem_size);
else
data = (BYTE*)Memory.mem_realloc(data, mem_size
#ifdef DEBUG_MEMORY_NAME
,
"CMemoryWriter - storage"
#endif // DEBUG_MEMORY_NAME
);
data = (BYTE*)Memory.mem_realloc(data, mem_size);
}
CopyMemory(data + position, ptr, count);
position += count;
Expand Down
2 changes: 0 additions & 2 deletions src/xrCore/xrCore.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@
<ClCompile Include="xrMemory_align.cpp" />
<ClCompile Include="xrMemory_debug.cpp" />
<ClCompile Include="xrMemory_POOL.cpp" />
<ClCompile Include="xrMemory_subst_borland.cpp" />
<ClCompile Include="xrMemory_subst_msvc.cpp" />
<ClCompile Include="xrsharedmem.cpp" />
<ClCompile Include="xrstring.cpp" />
Expand Down Expand Up @@ -357,7 +356,6 @@
<ClInclude Include="xrMemory.h" />
<ClInclude Include="xrMemory_align.h" />
<ClInclude Include="xrMemory_POOL.h" />
<ClInclude Include="xrMemory_subst_borland.h" />
<ClInclude Include="xrMemory_subst_msvc.h" />
<ClInclude Include="xrPool.h" />
<ClInclude Include="xrsharedmem.h" />
Expand Down
6 changes: 0 additions & 6 deletions src/xrCore/xrCore.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,6 @@
<ClCompile Include="xrMemory_POOL.cpp">
<Filter>Memory\Memory manager</Filter>
</ClCompile>
<ClCompile Include="xrMemory_subst_borland.cpp">
<Filter>Memory\Memory manager</Filter>
</ClCompile>
<ClCompile Include="xrMemory_subst_msvc.cpp">
<Filter>Memory\Memory manager</Filter>
</ClCompile>
Expand Down Expand Up @@ -512,9 +509,6 @@
<ClInclude Include="xrMemory_align.h">
<Filter>Memory\Memory manager</Filter>
</ClInclude>
<ClInclude Include="xrMemory_subst_borland.h">
<Filter>Memory\Memory manager</Filter>
</ClInclude>
<ClInclude Include="xrMemory_subst_msvc.h">
<Filter>Memory\Memory manager</Filter>
</ClInclude>
Expand Down
12 changes: 1 addition & 11 deletions src/xrCore/xrMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,7 @@ char* xr_strdup(const char* string)
{
VERIFY(string);
u32 len = u32(xr_strlen(string)) + 1;
char* memory = (char*)Memory.mem_alloc(len
#ifdef DEBUG_MEMORY_NAME
,
"strdup"
#endif // DEBUG_MEMORY_NAME
);
char* memory = (char*)Memory.mem_alloc(len);
CopyMemory(memory, string, len);
return memory;
}
Expand All @@ -279,10 +274,5 @@ XRCORE_API BOOL is_stack_ptr(void* _ptr)
return (difference < (512 * 1024));
}

#ifdef DEBUG_MEMORY_NAME
XRCORE_API void* xr_malloc(size_t size) { return Memory.mem_alloc(size, "xr_malloc"); }
XRCORE_API void* xr_realloc(void* P, size_t size) { return Memory.mem_realloc(P, size, "xr_realloc"); }
#else
XRCORE_API void* xr_malloc(size_t size) { return Memory.mem_alloc(size); }
XRCORE_API void* xr_realloc(void* P, size_t size) { return Memory.mem_realloc(P, size); }
#endif
13 changes: 1 addition & 12 deletions src/xrCore/xrMemory.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,9 @@ class XRCORE_API xrMemory
u32 mem_counter_get() { return stat_counter; }
#ifdef DEBUG_MEMORY_NAME
void mem_statistic(const char* fn);
void* mem_alloc(size_t size, const char* _name);
void* mem_realloc(void* p, size_t size, const char* _name);
#else // DEBUG_MEMORY_NAME
#endif // DEBUG_MEMORY_NAME
void* mem_alloc(size_t size);
void* mem_realloc(void* p, size_t size);
#endif // DEBUG_MEMORY_NAME
void mem_free(void* p);
};

Expand All @@ -98,18 +95,10 @@ extern XRCORE_API xrMemory Memory;
#endif

// generic "C"-like allocations/deallocations
#ifdef DEBUG_MEMORY_NAME
#include "typeinfo.h"
template <class T>
IC T* xr_alloc(size_t count)
{ return (T*)Memory.mem_alloc(count*sizeof(T), typeid(T).name()); }

#else
template <class T>
IC T* xr_alloc(size_t count)
{ return (T*)Memory.mem_alloc(count * sizeof(T)); }

#endif

template <class T>
IC void xr_free(T*& P) throw()
Expand Down
24 changes: 0 additions & 24 deletions src/xrCore/xrMemory_subst_borland.cpp

This file was deleted.

10 changes: 0 additions & 10 deletions src/xrCore/xrMemory_subst_borland.h

This file was deleted.

26 changes: 2 additions & 24 deletions src/xrCore/xrMemory_subst_msvc.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include "stdafx.h"
#include "xrMemory_align.h"

#ifndef __BORLANDC__

#ifndef DEBUG_MEMORY_MANAGER
#define debug_mode 0
#endif
Expand All @@ -14,6 +12,8 @@ extern void save_stack_trace();

MEMPOOL mem_pools[mem_pools_count];

constexpr pcstr _name = "_noname_";

// MSVC
ICF u8* acc_header(void* P) { return (u8*)P - 1; }
ICF u32 get_header(void* P) { return (u32)*acc_header(P); }
Expand All @@ -27,11 +27,7 @@ ICF u32 get_pool(size_t size)

static bool g_use_pure_alloc = false;

#ifdef DEBUG_MEMORY_NAME
void* xrMemory::mem_alloc(size_t size, const char* _name)
#else
void* xrMemory::mem_alloc(size_t size)
#endif
{
if (!size)
size = 1; // While allocationg 0 bytes is valid, let's mimic the old code for now.
Expand Down Expand Up @@ -138,11 +134,7 @@ void xrMemory::mem_free(void* P)

extern BOOL g_bDbgFillMemory;

#ifdef DEBUG_MEMORY_NAME
void* xrMemory::mem_realloc(void* P, size_t size, const char* _name)
#else
void* xrMemory::mem_realloc(void* P, size_t size)
#endif
{
stat_calls++;
if (g_use_pure_alloc)
Expand All @@ -156,11 +148,7 @@ void* xrMemory::mem_realloc(void* P, size_t size)
}
if (!P)
{
#ifdef DEBUG_MEMORY_NAME
return mem_alloc(size, _name);
#else
return mem_alloc(size);
#endif
}
#ifdef DEBUG_MEMORY_MANAGER
if (g_globalCheckAddr == P)
Expand Down Expand Up @@ -212,11 +200,7 @@ void* xrMemory::mem_realloc(void* P, size_t size)
u32 s_current = mem_pools[p_current].get_element();
u32 s_dest = (u32)size;
void* p_old = P;
#ifdef DEBUG_MEMORY_NAME
void* p_new = mem_alloc(size, _name);
#else
void* p_new = mem_alloc(size);
#endif
// Igor: Reserve 1 byte for xrMemory header
// Don't bother in this case?
memcpy(p_new, p_old, std::min(s_current - 1, s_dest));
Expand All @@ -227,11 +211,7 @@ void* xrMemory::mem_realloc(void* P, size_t size)
{
// relocate into another mmgr(pooled) from real
void* p_old = P;
#ifdef DEBUG_MEMORY_NAME
void* p_new = mem_alloc(size, _name);
#else
void* p_new = mem_alloc(size);
#endif
memcpy(p_new, p_old, (u32)size);
mem_free(p_old);
_ptr = p_new;
Expand All @@ -244,5 +224,3 @@ void* xrMemory::mem_realloc(void* P, size_t size)
#endif
return _ptr;
}

#endif // __BORLANDC__
7 changes: 1 addition & 6 deletions src/xrCore/xrsharedmem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,7 @@ smem_value* smem_container::dock(u32 dwCRC, u32 dwLength, void* ptr)
// if not found - create new entry
if (0 == result)
{
result = (smem_value*)Memory.mem_alloc(4 * sizeof(u32) + dwLength
#ifdef DEBUG_MEMORY_NAME
,
"storage: smem"
#endif // DEBUG_MEMORY_NAME
);
result = (smem_value*)Memory.mem_alloc(4 * sizeof(u32) + dwLength);
result->dwReference = 0;
result->dwCRC = dwCRC;
result->dwLength = dwLength;
Expand Down
7 changes: 1 addition & 6 deletions src/xrCore/xrstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,7 @@ str_value* str_container::dock(pcstr value)
#endif // DEBUG
)
{
result = (str_value*)Memory.mem_alloc(sizeof(str_value) + s_len_with_zero
#ifdef DEBUG_MEMORY_NAME
,
"storage: sstring"
#endif // DEBUG_MEMORY_NAME
);
result = (str_value*)Memory.mem_alloc(sizeof(str_value) + s_len_with_zero);

#ifdef DEBUG
static int num_leaked_string = 0;
Expand Down
5 changes: 0 additions & 5 deletions src/xrMisc/xrMisc_xrMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@
#endif

#ifndef NO_XRNEW
#ifdef DEBUG_MEMORY_NAME
void* operator new(size_t size) { return Memory.mem_alloc(size, "C++ NEW"); }
void* operator new[](size_t size) { return Memory.mem_alloc(size, "C++ NEW[]"); }
#else
void* operator new(size_t size) { return Memory.mem_alloc(size); }
void* operator new[](size_t size) { return Memory.mem_alloc(size); }
#endif

void operator delete(void* p) throw() { Memory.mem_free(p); }
void operator delete[](void* p) throw() { Memory.mem_free(p); }
Expand Down
12 changes: 0 additions & 12 deletions src/xrScriptEngine/script_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@ static void* lua_alloc(void* ud, void* ptr, size_t osize, size_t nsize)
xr_free(ptr);
return nullptr;
}
#ifdef DEBUG_MEMORY_NAME
return Memory.mem_realloc(ptr, nsize, "LUA");
#else
return Memory.mem_realloc(ptr, nsize);
#endif
}

static void* __cdecl luabind_allocator(void* context, const void* pointer, size_t const size)
Expand All @@ -67,18 +63,10 @@ static void* __cdecl luabind_allocator(void* context, const void* pointer, size_
}
if (!pointer)
{
#ifdef DEBUG_MEMORY_NAME
return Memory.mem_alloc(size, "luabind");
#else
return Memory.mem_alloc(size);
#endif
}
void* non_const_pointer = const_cast<LPVOID>(pointer);
#ifdef DEBUG_MEMORY_NAME
return Memory.mem_realloc(non_const_pointer, size, "luabind");
#else
return Memory.mem_realloc(non_const_pointer, size);
#endif
}

namespace
Expand Down

0 comments on commit 508755e

Please sign in to comment.