2012-03-28 13:24:49 +02:00
|
|
|
#include "i2-base.h"
|
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
2012-04-03 13:01:00 +02:00
|
|
|
Memory::Memory(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-03-28 13:24:49 +02:00
|
|
|
void *Memory::Allocate(size_t size)
|
|
|
|
{
|
|
|
|
void *ptr = malloc(size);
|
|
|
|
|
|
|
|
if (size != 0 && ptr == NULL)
|
2012-04-22 16:45:31 +02:00
|
|
|
throw OutOfMemoryException("malloc failed.");
|
2012-03-28 13:24:49 +02:00
|
|
|
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *Memory::Reallocate(void *ptr, size_t size)
|
|
|
|
{
|
|
|
|
void *new_ptr = realloc(ptr, size);
|
|
|
|
|
|
|
|
if (size != 0 && new_ptr == NULL)
|
2012-04-22 16:45:31 +02:00
|
|
|
throw OutOfMemoryException("realloc failed.");
|
2012-03-28 13:24:49 +02:00
|
|
|
|
|
|
|
return new_ptr;
|
|
|
|
}
|
|
|
|
|
2012-04-03 13:01:00 +02:00
|
|
|
char *Memory::StrDup(const char *str)
|
|
|
|
{
|
|
|
|
char *new_str = strdup(str);
|
|
|
|
|
|
|
|
if (str == NULL)
|
2012-04-22 16:45:31 +02:00
|
|
|
throw OutOfMemoryException("strdup failed.");
|
2012-04-03 13:01:00 +02:00
|
|
|
|
|
|
|
return new_str;
|
|
|
|
}
|
|
|
|
|
2012-03-28 13:24:49 +02:00
|
|
|
void Memory::Free(void *ptr)
|
|
|
|
{
|
|
|
|
if (ptr != NULL)
|
|
|
|
free(ptr);
|
|
|
|
}
|