Initialize the allocator and setup global data
| 1300 | |
| 1301 | //! Initialize the allocator and setup global data |
| 1302 | int |
| 1303 | rpmalloc_initialize(void) { |
| 1304 | #ifdef PLATFORM_WINDOWS |
| 1305 | SYSTEM_INFO system_info; |
| 1306 | memset(&system_info, 0, sizeof(system_info)); |
| 1307 | GetSystemInfo(&system_info); |
| 1308 | if (system_info.dwAllocationGranularity < SPAN_ADDRESS_GRANULARITY) |
| 1309 | return -1; |
| 1310 | #else |
| 1311 | #if ARCH_64BIT |
| 1312 | atomic_store64(&_memory_addr, 0x1000000000ULL); |
| 1313 | #else |
| 1314 | atomic_store64(&_memory_addr, 0x1000000ULL); |
| 1315 | #endif |
| 1316 | #endif |
| 1317 | |
| 1318 | atomic_store32(&_memory_heap_id, 0); |
| 1319 | |
| 1320 | //Setup all small and medium size classes |
| 1321 | size_t iclass; |
| 1322 | for (iclass = 0; iclass < SMALL_CLASS_COUNT; ++iclass) { |
| 1323 | size_t size = (iclass + 1) * SMALL_GRANULARITY; |
| 1324 | _memory_size_class[iclass].size = (uint16_t)size; |
| 1325 | _memory_adjust_size_class(iclass); |
| 1326 | } |
| 1327 | for (iclass = 0; iclass < MEDIUM_CLASS_COUNT; ++iclass) { |
| 1328 | size_t size = SMALL_SIZE_LIMIT + ((iclass + 1) * MEDIUM_GRANULARITY); |
| 1329 | if (size > MEDIUM_SIZE_LIMIT) |
| 1330 | size = MEDIUM_SIZE_LIMIT; |
| 1331 | _memory_size_class[SMALL_CLASS_COUNT + iclass].size = (uint16_t)size; |
| 1332 | _memory_adjust_size_class(SMALL_CLASS_COUNT + iclass); |
| 1333 | } |
| 1334 | |
| 1335 | //Initialize this thread |
| 1336 | rpmalloc_thread_initialize(); |
| 1337 | return 0; |
| 1338 | } |
| 1339 | |
| 1340 | //! Finalize the allocator |
| 1341 | void |
no test coverage detected