| 116 | } |
| 117 | |
| 118 | char * MemoryModel::allocate ( uint64_t size ) { |
| 119 | if ( !size ) return nullptr; |
| 120 | size = (size + alignMask) & ~alignMask; |
| 121 | totalAllocated += size; |
| 122 | maxAllocated = das::max(maxAllocated, totalAllocated); |
| 123 | if ( size > maxShoeAllocation ) { |
| 124 | char * ptr = (char *) das_aligned_alloc16(size); |
| 125 | bigStuff[ptr] = size; |
| 126 | #if DAS_TRACK_ALLOCATIONS |
| 127 | if ( trackAllocations ) { |
| 128 | INSCRIBE_INSANE_POINTER(ptr, this); |
| 129 | if ( g_tracker==g_breakpoint ) os_debug_break(); |
| 130 | bigStuffId[ptr] = g_tracker ++; |
| 131 | } |
| 132 | #endif |
| 133 | return ptr; |
| 134 | } else { |
| 135 | if ( char * res = shoe.allocate(uint32_t(size)) ) { |
| 136 | return res; |
| 137 | } |
| 138 | size = (size + 15) & ~15; |
| 139 | DAS_ASSERT(size && size<=DAS_MAX_SHOE_ALLOCATION); |
| 140 | uint32_t si = uint32_t((size >> 4) - 1); |
| 141 | uint64_t total = grow(si); |
| 142 | shoe.chunks[si] = new Deck(total, uint32_t(size), shoe.chunks[si]); |
| 143 | return shoe.chunks[si]->allocate(); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | bool MemoryModel::free ( char * ptr, uint64_t size ) { |
| 148 | if ( !size ) return true; |