Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ if(NOT WIN32)
endif()

option ( TBB_PARALLEL "Use tbb::parallel for prarticle and skinning acceleration on SMP." ON )
option ( NO_TBB_MALLOC "Use standard memory allocation instead of tbbmalloc" ON )

include(cotire)

Expand Down Expand Up @@ -85,6 +86,10 @@ if( TBB_PARALLEL )
add_definitions ( -DUSE_TBB_PARALLEL )
endif()

if( NO_TBB_MALLOC )
add_definitions ( -DNO_TBB_MALLOC )
endif()

if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
add_definitions(-DDEBUG -DMIXED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Og")
Expand Down
2 changes: 1 addition & 1 deletion src/xrCommon/xr_deque.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <deque>
#include "xrCore/xrMemory.h"

template <typename T, typename allocator = tbb::tbb_allocator<T>>
template <typename T, typename allocator = xr_allocator<T>>
using xr_deque = std::deque<T, allocator>;

#define DEF_DEQUE(N, T)\
Expand Down
2 changes: 1 addition & 1 deletion src/xrCommon/xr_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <list>
#include "xrCore/xrMemory.h"

template <typename T, typename allocator = tbb::tbb_allocator<T>>
template <typename T, typename allocator = xr_allocator<T>>
using xr_list = std::list<T, allocator>;

#define DEF_LIST(N, T)\
Expand Down
4 changes: 2 additions & 2 deletions src/xrCommon/xr_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
#include <map>
#include "xrCore/xrMemory.h"

template <typename K, class V, class P = std::less<K>, typename allocator = tbb::tbb_allocator<std::pair<const K, V>>>
template <typename K, class V, class P = std::less<K>, typename allocator = xr_allocator<std::pair<const K, V>>>
using xr_map = std::map<K, V, P, allocator>;

template <typename K, class V, class P = std::less<K>, typename allocator = tbb::tbb_allocator<std::pair<const K, V>>>
template <typename K, class V, class P = std::less<K>, typename allocator = xr_allocator<std::pair<const K, V>>>
using xr_multimap = std::multimap<K, V, P, allocator>;

#define DEF_MAP(N, K, T)\
Expand Down
4 changes: 2 additions & 2 deletions src/xrCommon/xr_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
#include <set>
#include "xrCore/xrMemory.h"

template <typename K, class P = std::less<K>, typename allocator = tbb::tbb_allocator<K>>
template <typename K, class P = std::less<K>, typename allocator = xr_allocator<K>>
using xr_set = std::set<K, P, allocator>;

template <typename K, class P = std::less<K>, typename allocator = tbb::tbb_allocator<K>>
template <typename K, class P = std::less<K>, typename allocator = xr_allocator<K>>
using xr_multiset = std::multiset<K, P, allocator>;

#define DEFINE_SET(T, N, I)\
Expand Down
2 changes: 1 addition & 1 deletion src/xrCommon/xr_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "xrCore/xrMemory.h"

// string(char)
using xr_string = std::basic_string<char, std::char_traits<char>, tbb::tbb_allocator<char>>;
using xr_string = std::basic_string<char, std::char_traits<char>, xr_allocator<char>>;

inline void xr_strlwr(xr_string& src)
{
Expand Down
2 changes: 1 addition & 1 deletion src/xrCommon/xr_unordered_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
#include "xrCore/xrMemory.h"

template <typename K, class V, class Hasher = std::hash<K>, class Traits = std::equal_to<K>,
typename allocator = tbb::tbb_allocator<std::pair<const K, V>>>
typename allocator = xr_allocator<std::pair<const K, V>>>
using xr_unordered_map = std::unordered_map<K, V, Hasher, Traits, allocator>;
2 changes: 1 addition & 1 deletion src/xrCommon/xr_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <vector>
#include "xrCore/xrMemory.h"

template <typename T, typename allocator = tbb::tbb_allocator<T>>
template <typename T, typename allocator = xr_allocator<T>>
using xr_vector = std::vector<T, allocator>;

#define DEF_VECTOR(N, T)\
Expand Down
2 changes: 2 additions & 0 deletions src/xrCore/xrMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ void xrMemory::mem_compact()
которые требуют большие свободные области памяти.
Но всё-же чистку tbb, возможно, стоит оставить. Но и это под большим вопросом.
*/
#ifndef NO_TBB_MALLOC
scalable_allocation_command(TBBMALLOC_CLEAN_ALL_BUFFERS, nullptr);
#endif
//HeapCompact(GetProcessHeap(), 0);
if (g_pStringContainer)
g_pStringContainer->clean();
Expand Down
43 changes: 37 additions & 6 deletions src/xrCore/xrMemory.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

#include "_types.h"

#include <tbb/tbb_allocator.h>
#include <tbb/scalable_allocator.h>

/*
Можно заключить - прокси перехватывает не всегда и/или не всё используемые функции.
И в очень малом количестве случаев это приводит к странностям при работе с памятью.
Expand All @@ -15,6 +12,25 @@
//#include "tbb/tbbmalloc_proxy.h" // Xottab_DUTY: works bad, disabled it..
#endif

#if defined(NO_TBB_MALLOC)
template <typename T>
using xr_allocator = std::allocator<T>;
#define xr_internal_malloc malloc
#define xr_internal_realloc realloc
#define xr_internal_free free

#else
#include <tbb/tbb_allocator.h>
#include <tbb/scalable_allocator.h>

template <typename T>
using xr_allocator = tbb::scalable_allocator<T>;
#define xr_internal_malloc scalable_malloc
#define xr_internal_realloc scalable_realloc
#define xr_internal_free scalable_free
#endif


class XRCORE_API xrMemory
{
// Additional 16 bytes of memory almost like in original xr_aligned_offset_malloc
Expand All @@ -35,9 +51,24 @@ class XRCORE_API xrMemory
public:
size_t mem_usage();
void mem_compact();
inline void* mem_alloc (size_t size) { stat_calls++; return scalable_malloc ( size + reserved); }
inline void* mem_realloc(void* ptr, size_t size) { stat_calls++; return scalable_realloc(ptr, size + reserved); }
inline void mem_free (void* ptr) { stat_calls++; scalable_free (ptr); }

inline void* mem_alloc(size_t size)
{
stat_calls++;
return xr_internal_malloc(size + reserved);
}

inline void* mem_realloc(void* ptr, size_t new_size)
{
stat_calls++;
return xr_internal_realloc(ptr, new_size + reserved);
}

inline void mem_free(void* ptr)
{
stat_calls++;
xr_internal_free(ptr);
}
};

extern XRCORE_API xrMemory Memory;
Expand Down