Commit 150766bb authored by Davis King's avatar Davis King

Made memory managers use size_t to measure memory allocation sizes rather than unsigned long.

parent ab946d7f
...@@ -106,6 +106,7 @@ namespace std ...@@ -106,6 +106,7 @@ namespace std
#include <algorithm> // for std::swap #include <algorithm> // for std::swap
#include <new> // for std::bad_alloc #include <new> // for std::bad_alloc
#include <cstdlib> #include <cstdlib>
#include <stddef.h>
#include <limits> // for std::numeric_limits for is_finite() #include <limits> // for std::numeric_limits for is_finite()
#include "assert.h" #include "assert.h"
#include "error.h" #include "error.h"
......
...@@ -14,7 +14,7 @@ namespace dlib ...@@ -14,7 +14,7 @@ namespace dlib
template < template <
typename T, typename T,
unsigned long max_pool_size size_t max_pool_size
> >
class memory_manager_kernel_1 class memory_manager_kernel_1
{ {
...@@ -86,11 +86,11 @@ namespace dlib ...@@ -86,11 +86,11 @@ namespace dlib
} }
} }
unsigned long get_number_of_allocations ( size_t get_number_of_allocations (
) const { return allocations; } ) const { return allocations; }
T* allocate_array ( T* allocate_array (
unsigned long size size_t size
) )
{ {
T* temp = new T[size]; T* temp = new T[size];
...@@ -183,9 +183,9 @@ namespace dlib ...@@ -183,9 +183,9 @@ namespace dlib
private: private:
// data members // data members
unsigned long allocations; size_t allocations;
node* next; node* next;
unsigned long pool_size; size_t pool_size;
// restricted functions // restricted functions
memory_manager_kernel_1(memory_manager_kernel_1&); // copy constructor memory_manager_kernel_1(memory_manager_kernel_1&); // copy constructor
...@@ -231,11 +231,11 @@ namespace dlib ...@@ -231,11 +231,11 @@ namespace dlib
{ {
} }
unsigned long get_number_of_allocations ( size_t get_number_of_allocations (
) const { return allocations; } ) const { return allocations; }
T* allocate_array ( T* allocate_array (
unsigned long size size_t size
) )
{ {
T* temp = new T[size]; T* temp = new T[size];
...@@ -277,7 +277,7 @@ namespace dlib ...@@ -277,7 +277,7 @@ namespace dlib
private: private:
// data members // data members
unsigned long allocations; size_t allocations;
// restricted functions // restricted functions
memory_manager_kernel_1(memory_manager_kernel_1&); // copy constructor memory_manager_kernel_1(memory_manager_kernel_1&); // copy constructor
...@@ -288,7 +288,7 @@ namespace dlib ...@@ -288,7 +288,7 @@ namespace dlib
template < template <
typename T, typename T,
unsigned long max_pool_size size_t max_pool_size
> >
inline void swap ( inline void swap (
memory_manager_kernel_1<T,max_pool_size>& a, memory_manager_kernel_1<T,max_pool_size>& a,
......
...@@ -13,7 +13,7 @@ namespace dlib ...@@ -13,7 +13,7 @@ namespace dlib
template < template <
typename T, typename T,
unsigned long chunk_size size_t chunk_size
> >
class memory_manager_kernel_2 class memory_manager_kernel_2
{ {
...@@ -103,11 +103,11 @@ namespace dlib ...@@ -103,11 +103,11 @@ namespace dlib
} }
} }
unsigned long get_number_of_allocations ( size_t get_number_of_allocations (
) const { return allocations; } ) const { return allocations; }
T* allocate_array ( T* allocate_array (
unsigned long size size_t size
) )
{ {
T* temp = new T[size]; T* temp = new T[size];
...@@ -184,7 +184,7 @@ namespace dlib ...@@ -184,7 +184,7 @@ namespace dlib
++block; ++block;
// now add the rest of the block into the linked list of free nodes. // now add the rest of the block into the linked list of free nodes.
for (unsigned long i = 0; i < chunk_size-1; ++i) for (size_t i = 0; i < chunk_size-1; ++i)
{ {
block->next = next; block->next = next;
next = block; next = block;
...@@ -223,7 +223,7 @@ namespace dlib ...@@ -223,7 +223,7 @@ namespace dlib
private: private:
// data members // data members
unsigned long allocations; size_t allocations;
node* next; node* next;
chunk_node* first_chunk; chunk_node* first_chunk;
...@@ -238,7 +238,7 @@ namespace dlib ...@@ -238,7 +238,7 @@ namespace dlib
template < template <
typename T, typename T,
unsigned long chunk_size size_t chunk_size
> >
inline void swap ( inline void swap (
memory_manager_kernel_2<T,chunk_size>& a, memory_manager_kernel_2<T,chunk_size>& a,
......
...@@ -16,7 +16,7 @@ namespace dlib ...@@ -16,7 +16,7 @@ namespace dlib
template < template <
typename T, typename T,
unsigned long chunk_size size_t chunk_size
> >
class memory_manager_kernel_3 class memory_manager_kernel_3
{ {
...@@ -126,11 +126,11 @@ namespace dlib ...@@ -126,11 +126,11 @@ namespace dlib
} }
} }
unsigned long get_number_of_allocations ( size_t get_number_of_allocations (
) const { return allocations; } ) const { return allocations; }
T* allocate_array ( T* allocate_array (
unsigned long size size_t size
) )
{ {
size_t block_size = sizeof(T)*size + sizeof(size_t)*2; size_t block_size = sizeof(T)*size + sizeof(size_t)*2;
...@@ -252,7 +252,7 @@ namespace dlib ...@@ -252,7 +252,7 @@ namespace dlib
++block; ++block;
// now add the rest of the block into the linked list of free nodes. // now add the rest of the block into the linked list of free nodes.
for (unsigned long i = 0; i < chunk_size-1; ++i) for (size_t i = 0; i < chunk_size-1; ++i)
{ {
block->next = next; block->next = next;
next = block; next = block;
...@@ -292,7 +292,7 @@ namespace dlib ...@@ -292,7 +292,7 @@ namespace dlib
private: private:
// data members // data members
unsigned long allocations; size_t allocations;
node* next; node* next;
chunk_node* first_chunk; chunk_node* first_chunk;
...@@ -370,7 +370,7 @@ namespace dlib ...@@ -370,7 +370,7 @@ namespace dlib
template < template <
typename T, typename T,
unsigned long chunk_size size_t chunk_size
> >
inline void swap ( inline void swap (
memory_manager_kernel_3<T,chunk_size>& a, memory_manager_kernel_3<T,chunk_size>& a,
......
...@@ -52,7 +52,7 @@ namespace dlib ...@@ -52,7 +52,7 @@ namespace dlib
causes a memory leak. causes a memory leak.
!*/ !*/
unsigned long get_number_of_allocations ( size_t get_number_of_allocations (
) const; ) const;
/*! /*!
ensures ensures
...@@ -86,7 +86,7 @@ namespace dlib ...@@ -86,7 +86,7 @@ namespace dlib
!*/ !*/
T* allocate_array ( T* allocate_array (
unsigned long size size_t size
); );
/*! /*!
ensures ensures
......
...@@ -43,7 +43,7 @@ namespace dlib ...@@ -43,7 +43,7 @@ namespace dlib
virtual ~memory_manager_global_kernel_1( virtual ~memory_manager_global_kernel_1(
) {} ) {}
unsigned long get_number_of_allocations ( size_t get_number_of_allocations (
) const { return global_mm->get_number_of_allocations(); } ) const { return global_mm->get_number_of_allocations(); }
mm_global_type& get_global_memory_manager ( mm_global_type& get_global_memory_manager (
...@@ -63,7 +63,7 @@ namespace dlib ...@@ -63,7 +63,7 @@ namespace dlib
} }
T* allocate_array ( T* allocate_array (
unsigned long size size_t size
) )
{ {
return global_mm->allocate_array(size); return global_mm->allocate_array(size);
......
...@@ -81,7 +81,7 @@ namespace dlib ...@@ -81,7 +81,7 @@ namespace dlib
get_global_memory_manager(). get_global_memory_manager().
!*/ !*/
unsigned long get_number_of_allocations ( size_t get_number_of_allocations (
) const; ) const;
/*! /*!
ensures ensures
...@@ -122,7 +122,7 @@ namespace dlib ...@@ -122,7 +122,7 @@ namespace dlib
!*/ !*/
T* allocate_array ( T* allocate_array (
unsigned long size size_t size
); );
/*! /*!
ensures ensures
......
...@@ -48,7 +48,7 @@ namespace dlib ...@@ -48,7 +48,7 @@ namespace dlib
} }
T* allocate_array ( T* allocate_array (
unsigned long size size_t size
) )
{ {
return new T[size]; return new T[size];
......
...@@ -60,7 +60,7 @@ namespace dlib ...@@ -60,7 +60,7 @@ namespace dlib
} }
T* allocate_array ( T* allocate_array (
unsigned long size size_t size
) )
{ {
auto_mutex M(global_mutex()); auto_mutex M(global_mutex());
......
...@@ -82,7 +82,7 @@ namespace dlib ...@@ -82,7 +82,7 @@ namespace dlib
!*/ !*/
T* allocate_array ( T* allocate_array (
unsigned long size size_t size
); );
/*! /*!
ensures ensures
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment