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
#include <algorithm> // for std::swap
#include <new> // for std::bad_alloc
#include <cstdlib>
#include <stddef.h>
#include <limits> // for std::numeric_limits for is_finite()
#include "assert.h"
#include "error.h"
......
......@@ -14,7 +14,7 @@ namespace dlib
template <
typename T,
unsigned long max_pool_size
size_t max_pool_size
>
class memory_manager_kernel_1
{
......@@ -86,11 +86,11 @@ namespace dlib
}
}
unsigned long get_number_of_allocations (
size_t get_number_of_allocations (
) const { return allocations; }
T* allocate_array (
unsigned long size
size_t size
)
{
T* temp = new T[size];
......@@ -183,9 +183,9 @@ namespace dlib
private:
// data members
unsigned long allocations;
size_t allocations;
node* next;
unsigned long pool_size;
size_t pool_size;
// restricted functions
memory_manager_kernel_1(memory_manager_kernel_1&); // copy constructor
......@@ -231,11 +231,11 @@ namespace dlib
{
}
unsigned long get_number_of_allocations (
size_t get_number_of_allocations (
) const { return allocations; }
T* allocate_array (
unsigned long size
size_t size
)
{
T* temp = new T[size];
......@@ -277,7 +277,7 @@ namespace dlib
private:
// data members
unsigned long allocations;
size_t allocations;
// restricted functions
memory_manager_kernel_1(memory_manager_kernel_1&); // copy constructor
......@@ -288,7 +288,7 @@ namespace dlib
template <
typename T,
unsigned long max_pool_size
size_t max_pool_size
>
inline void swap (
memory_manager_kernel_1<T,max_pool_size>& a,
......
......@@ -13,7 +13,7 @@ namespace dlib
template <
typename T,
unsigned long chunk_size
size_t chunk_size
>
class memory_manager_kernel_2
{
......@@ -103,11 +103,11 @@ namespace dlib
}
}
unsigned long get_number_of_allocations (
size_t get_number_of_allocations (
) const { return allocations; }
T* allocate_array (
unsigned long size
size_t size
)
{
T* temp = new T[size];
......@@ -184,7 +184,7 @@ namespace dlib
++block;
// 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;
next = block;
......@@ -223,7 +223,7 @@ namespace dlib
private:
// data members
unsigned long allocations;
size_t allocations;
node* next;
chunk_node* first_chunk;
......@@ -238,7 +238,7 @@ namespace dlib
template <
typename T,
unsigned long chunk_size
size_t chunk_size
>
inline void swap (
memory_manager_kernel_2<T,chunk_size>& a,
......
......@@ -16,7 +16,7 @@ namespace dlib
template <
typename T,
unsigned long chunk_size
size_t chunk_size
>
class memory_manager_kernel_3
{
......@@ -126,11 +126,11 @@ namespace dlib
}
}
unsigned long get_number_of_allocations (
size_t get_number_of_allocations (
) const { return allocations; }
T* allocate_array (
unsigned long size
size_t size
)
{
size_t block_size = sizeof(T)*size + sizeof(size_t)*2;
......@@ -252,7 +252,7 @@ namespace dlib
++block;
// 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;
next = block;
......@@ -292,7 +292,7 @@ namespace dlib
private:
// data members
unsigned long allocations;
size_t allocations;
node* next;
chunk_node* first_chunk;
......@@ -370,7 +370,7 @@ namespace dlib
template <
typename T,
unsigned long chunk_size
size_t chunk_size
>
inline void swap (
memory_manager_kernel_3<T,chunk_size>& a,
......
......@@ -52,7 +52,7 @@ namespace dlib
causes a memory leak.
!*/
unsigned long get_number_of_allocations (
size_t get_number_of_allocations (
) const;
/*!
ensures
......@@ -86,7 +86,7 @@ namespace dlib
!*/
T* allocate_array (
unsigned long size
size_t size
);
/*!
ensures
......
......@@ -43,7 +43,7 @@ namespace dlib
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(); }
mm_global_type& get_global_memory_manager (
......@@ -63,7 +63,7 @@ namespace dlib
}
T* allocate_array (
unsigned long size
size_t size
)
{
return global_mm->allocate_array(size);
......
......@@ -81,7 +81,7 @@ namespace dlib
get_global_memory_manager().
!*/
unsigned long get_number_of_allocations (
size_t get_number_of_allocations (
) const;
/*!
ensures
......@@ -122,7 +122,7 @@ namespace dlib
!*/
T* allocate_array (
unsigned long size
size_t size
);
/*!
ensures
......
......@@ -48,7 +48,7 @@ namespace dlib
}
T* allocate_array (
unsigned long size
size_t size
)
{
return new T[size];
......
......@@ -60,7 +60,7 @@ namespace dlib
}
T* allocate_array (
unsigned long size
size_t size
)
{
auto_mutex M(global_mutex());
......
......@@ -82,7 +82,7 @@ namespace dlib
!*/
T* allocate_array (
unsigned long size
size_t size
);
/*!
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