memory_operation wrapped_realloc(void* ptr, size_t size) { START_TEST(type_id, FunctionCalls::REALLOC) data.ptr = memkind_realloc(kind, ptr, size); data.error_code = errno; END_TEST }
TEST_F(MemkindPmemTests, test_TC_MEMKIND_PmemRealloc) { const size_t size1 = 512; const size_t size2 = 1024; char *default_str = NULL; default_str = (char *)memkind_realloc(pmem_kind, default_str, size1); EXPECT_TRUE(NULL != default_str); sprintf(default_str, "memkind_realloc MEMKIND_PMEM with size %zu\n", size1); printf("%s", default_str); default_str = (char *)memkind_realloc(pmem_kind, default_str, size2); EXPECT_TRUE(NULL != default_str); sprintf(default_str, "memkind_realloc MEMKIND_PMEM with size %zu\n", size2); printf("%s", default_str); memkind_free(pmem_kind, default_str); }
TEST_F(MemkindDefaultTests, test_TC_MEMKIND_DefaultRealloc) { const size_t size1 = 512; const size_t size2 = 1024; char *default_str = NULL; default_str = (char *)memkind_realloc(MEMKIND_DEFAULT, default_str, size1); EXPECT_TRUE(NULL != default_str); sprintf(default_str, "memkind_realloc MEMKIND_DEFAULT with size %zu\n", size1); printf("%s", default_str); default_str = (char *)memkind_realloc(MEMKIND_DEFAULT, default_str, size2); EXPECT_TRUE(NULL != default_str); sprintf(default_str, "memkind_realloc MEMKIND_DEFAULT with size %zu\n", size2); printf("%s", default_str); memkind_free(MEMKIND_DEFAULT, default_str); }
//////////////////////////////////////////////////////////////////////////// // My realloc implementation calling memkind_realloc //////////////////////////////////////////////////////////////////////////// void *myMemkindRealloc(void *ptr, size_t size) { DBG(2) printf("In my memkind realloc sz:%ld, p1:%p ..", size, ptr); void *pp; // if we have not initialized memkind HBW arena yet, call default kind // if (!MemkindInitDone || !isAllocInHBW(size)) pp = memkind_realloc(MEMKIND_DEFAULT, ptr, size); else { DBG(2) printf("\tHBW"); pp = memkind_realloc(HBW_Type, ptr, size); logHBW(pp, size); } DBG(2) printf("\tptr=%p\n", pp); return pp; }
void *hbw_realloc(void *ptr, size_t size) { int i; memkind_t kind; memkind_t gbtlb_kinds[3] = {MEMKIND_HBW_GBTLB, MEMKIND_HBW_PREFERRED_GBTLB, MEMKIND_GBTLB}; for (i = 0; i < 3; i++) { kind = gbtlb_kinds[i]; if (kind->ops->check_addr(kind, ptr) == 0) { i = -1; break; } } if (i != -1) { kind = hbw_get_kind(HBW_PAGESIZE_4KB); } return memkind_realloc(kind, ptr, size); }
MEMKIND_EXPORT void *hbw_realloc(void *ptr, size_t size) { return memkind_realloc(hbw_get_kind(HBW_PAGESIZE_4KB), ptr, size); }
void* mca_mpool_memkind_realloc(mca_mpool_base_module_t *mpool, void *addr, size_t size) { mca_mpool_memkind_module_t *memkind_module = (mca_mpool_memkind_module_t *) mpool; return memkind_realloc (memkind_module->kind, addr, size); }