diff options
| -rw-r--r-- | pkmem.h | 4 | ||||
| -rw-r--r-- | test/pkmem.cpp | 17 |
2 files changed, 19 insertions, 2 deletions
@@ -552,8 +552,8 @@ pk_delete_bkt(const void* ptr, size_t sz, struct pk_membucket* bkt) bkt->head = 0; bkt->block_head_l = 0; bkt->block_head_r = 0; - bkt->blocks[0].data = pk_bkt_data(bkt); - bkt->blocks[0].size = pk_bkt_data_sz(bkt); + bkt->blocks[pk_memblock_blocks_idx(bkt, 0)].data = pk_bkt_data(bkt); + bkt->blocks[pk_memblock_blocks_idx(bkt, 0)].size = pk_bkt_data_sz(bkt); #ifdef PK_MEMORY_DEBUGGER bkt->debug_head_l = 0; bkt->debug_head_r = 0; diff --git a/test/pkmem.cpp b/test/pkmem.cpp index 52b393b..c19b71d 100644 --- a/test/pkmem.cpp +++ b/test/pkmem.cpp @@ -122,6 +122,7 @@ const char *test_bucket_count02 = "test_bucket_count02"; const char *test_bucket_count03 = "test_bucket_count03"; const char *test_bucket_count04 = "test_bucket_count04"; const char *test_bucket_count05 = "test_bucket_count05"; +const char *test_generic_01 = "test_generic_01"; void pk_test_pkmem_spinup(bool init_funcinstr = false) { if (init_funcinstr) pk_funcinstr_init(); @@ -648,5 +649,21 @@ int main(int argc, char *argv[]) fprintf(stdout, "[pkmem.cpp] end: %s\n\n", test_alloc_strings); pk_test_pkmem_teardown(); + // ensures that pk_delete resets the bkt when alloc_count falls to 0 + pk_test_pkmem_spinup(); + fprintf(stdout, "[pkmem.cpp] start: %s\n", test_generic_01); + { + pk_membucket *bkt = pk_mem_bucket_create(test_free_between, PK_MEM_DEFAULT_BUCKET_SIZE, PK_MEMBUCKET_FLAG_NONE); + + float *flts1 = pk_new<float>(48000, bkt); + pk_delete<float>(flts1, 48000, bkt); + float *flts2 = pk_new<float>(48000, bkt); + pk_delete<float>(flts2, 48000, bkt); + + pk_mem_bucket_destroy(bkt); + } + fprintf(stdout, "[pkmem.cpp] end: %s\n\n", test_alloc_strings); + pk_test_pkmem_teardown(); + return 0; } |
