Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #pragma once
00015
00019 #include <malloc.h>
00020 #include <cassert>
00021
00022 #include "Allocator.h"
00023 #include "Alignment.h"
00024
00025 namespace kNet
00026 {
00030 class StdCAlloc
00031 {
00032 public:
00033
00034
00035
00036
00037 static inline void *Alloc(StdCAlloc *, size_t size, size_t alignment, const char * = 0, AllocFlags = AFAllocLow)
00038 {
00039 assert(IS_POW2(alignment));
00040 #ifdef WIN32
00041 void *ptr = _aligned_malloc(size, alignment);
00042 #else
00043 void *ptr = malloc(size);
00044 #endif
00045 return ptr;
00046 }
00047 static inline void Free(StdCAlloc *, void *ptr)
00048 {
00049 #ifdef WIN32
00050 _aligned_free(ptr);
00051 #else
00052 free(ptr);
00053 #endif
00054 }
00055
00057 static inline size_t Size(StdCAlloc *, void *ptr)
00058 {
00059 #ifdef WIN32
00060 return ::_msize(ptr);
00061 #else
00062 assert(false && "N/I");
00063 return 0;
00064 #endif
00065 }
00066 };
00067
00068 }