14 #include <shogun/lib/config.h> 17 #ifndef DOXYGEN_SHOULD_SKIP_THIS 26 template <
class InputIt,
class OutputIt>
29 return std::memcpy(static_cast<void*>(dest), static_cast<const void*>(src), count);
37 void*
operator new(
size_t size)
throw (std::bad_alloc);
38 void operator delete(
void *p)
throw();
41 void*
operator new[](
size_t size)
throw(std::bad_alloc);
42 void operator delete[](
void *p)
throw();
44 #ifdef TRACE_MEMORY_ALLOCS 45 #define SG_MALLOC(type, len) sg_generic_malloc<type>(size_t(len), __FILE__, __LINE__) 46 #define SG_CALLOC(type, len) sg_generic_calloc<type>(size_t(len), __FILE__, __LINE__) 47 #define SG_REALLOC(type, ptr, old_len, len) sg_generic_realloc<type>(ptr, size_t(old_len), size_t(len), __FILE__, __LINE__) 48 #define SG_FREE(ptr) sg_generic_free(ptr) 49 #else //TRACE_MEMORY_ALLOCS 51 #define SG_MALLOC(type, len) sg_generic_malloc<type>(size_t(len)) 52 #define SG_CALLOC(type, len) sg_generic_calloc<type>(size_t(len)) 53 #define SG_REALLOC(type, ptr, old_len, len) sg_generic_realloc<type>(ptr, size_t(old_len), size_t(len)) 54 #define SG_FREE(ptr) sg_generic_free(ptr) 55 #endif //TRACE_MEMORY_ALLOCS 59 template <
class T>
class SGVector;
60 template <
class T>
class SGSparseVector;
61 template <
class T>
class SGMatrix;
63 #ifdef TRACE_MEMORY_ALLOCS 64 void*
sg_malloc(
size_t size,
const char* file,
int line);
65 template <
class T> T* sg_generic_malloc(
size_t len,
const char* file,
int line)
67 return (T*)
sg_malloc(
sizeof(T)*len, file, line);
70 void*
sg_calloc(
size_t num,
size_t size,
const char* file,
int line);
71 template <
class T> T* sg_generic_calloc(
size_t len,
const char* file,
int line)
73 return (T*)
sg_calloc(len,
sizeof(T), file, line);
76 void*
sg_realloc(
void* ptr,
size_t size,
const char* file,
int line);
77 template <
class T> T* sg_generic_realloc(T* ptr,
size_t old_len,
size_t len,
const char* file,
int line)
79 return (T*)
sg_realloc(ptr,
sizeof(T)*len, file, line);
83 template <
class T>
void sg_generic_free(T* ptr)
87 #else //TRACE_MEMORY_ALLOCS 89 template <
class T> T* sg_generic_malloc(
size_t len)
95 template <
class T> T* sg_generic_realloc(T* ptr,
size_t old_len,
size_t len)
100 void*
sg_calloc(
size_t num,
size_t size);
101 template <
class T> T* sg_generic_calloc(
size_t len)
107 template <
class T>
void sg_generic_free(T* ptr)
111 #endif //TRACE_MEMORY_ALLOCS 112 #ifdef TRACE_MEMORY_ALLOCS 123 MemoryBlock(
void* p);
130 MemoryBlock(
void* p,
size_t sz,
const char* fname=NULL,
int linenr=-1);
134 MemoryBlock(
const MemoryBlock &b);
152 void list_memory_allocs();
155 #ifdef TRACE_MEMORY_ALLOCS 156 #define SG_SPECIALIZED_MALLOC(type) \ 157 template<> type* sg_generic_malloc<type >(size_t len, const char* file, int line); \ 158 template<> type* sg_generic_calloc<type >(size_t len, const char* file, int line); \ 159 template<> type* sg_generic_realloc<type >(type* ptr, size_t old_len, size_t len, const char* file, int line); \ 160 template<> void sg_generic_free<type >(type* ptr); 161 #else // TRACE_MEMORY_ALLOCS 162 #define SG_SPECIALIZED_MALLOC(type) \ 163 template<> type* sg_generic_malloc<type >(size_t len); \ 164 template<> type* sg_generic_calloc<type >(size_t len); \ 165 template<> type* sg_generic_realloc<type >(type* ptr, size_t old_len, size_t len); \ 166 template<> void sg_generic_free<type >(type* ptr); 167 #endif // TRACE_MEMORY_ALLOCS 213 #undef SG_SPECIALIZED_MALLOC 215 void* get_copy(
void* src,
size_t len);
216 char* get_strdup(
const char* str);
219 #endif // DOXYGEN_SHOULD_SKIP_THIS 221 #endif // __MEMORY_H__ void * sg_calloc(size_t num, size_t size)
bool operator==(const Any &lhs, const Any &rhs)
void * sg_malloc(size_t size)
all of classes and functions are contained in the shogun namespace
#define SG_SPECIALIZED_MALLOC(type)
void * sg_realloc(void *ptr, size_t size)