@@ -29,6 +29,8 @@ Copyright (c) 2015 Microsoft Corporation
29
29
# define malloc_usable_size _msize
30
30
#endif
31
31
32
+ #define SIZE_T_ALIGN 2
33
+
32
34
// The following two function are automatically generated by the mk_make.py script.
33
35
// The script collects ADD_INITIALIZER and ADD_FINALIZER commands in the .h files.
34
36
// For example, rational.h contains
@@ -278,7 +280,7 @@ void memory::deallocate(void * p) {
278
280
size_t sz = malloc_usable_size (p);
279
281
void * real_p = p;
280
282
#else
281
- size_t * sz_p = reinterpret_cast <size_t *>(p) - 1 ;
283
+ size_t * sz_p = reinterpret_cast <size_t *>(p) - SIZE_T_ALIGN ;
282
284
size_t sz = *sz_p;
283
285
void * real_p = reinterpret_cast <void *>(sz_p);
284
286
#endif
@@ -291,7 +293,7 @@ void memory::deallocate(void * p) {
291
293
292
294
void * memory::allocate (size_t s) {
293
295
#ifndef HAS_MALLOC_USABLE_SIZE
294
- s = s + sizeof (size_t ); // we allocate an extra field!
296
+ s = s + SIZE_T_ALIGN * sizeof (size_t ); // we allocate an extra field!
295
297
#endif
296
298
g_memory_thread_alloc_size += s;
297
299
g_memory_thread_alloc_count += 1 ;
@@ -308,7 +310,7 @@ void * memory::allocate(size_t s) {
308
310
return r;
309
311
#else
310
312
*(static_cast <size_t *>(r)) = s;
311
- return static_cast <size_t *>(r) + 1 ; // we return a pointer to the location after the extra field
313
+ return static_cast <size_t *>(r) + SIZE_T_ALIGN ; // we return a pointer to the location after the extra field
312
314
#endif
313
315
}
314
316
@@ -323,7 +325,7 @@ void* memory::reallocate(void *p, size_t s) {
323
325
size_t *sz_p = reinterpret_cast <size_t *>(p)-1 ;
324
326
size_t sz = *sz_p;
325
327
void *real_p = reinterpret_cast <void *>(sz_p);
326
- s = s + sizeof (size_t ); // we allocate an extra field!
328
+ s = s + SIZE_T_ALIGN * sizeof (size_t ); // we allocate an extra field!
327
329
#endif
328
330
g_memory_thread_alloc_size += s - sz;
329
331
g_memory_thread_alloc_count += 1 ;
@@ -341,7 +343,7 @@ void* memory::reallocate(void *p, size_t s) {
341
343
return r;
342
344
#else
343
345
*(static_cast <size_t *>(r)) = s;
344
- return static_cast <size_t *>(r) + 1 ; // we return a pointer to the location after the extra field
346
+ return static_cast <size_t *>(r) + SIZE_T_ALIGN ; // we return a pointer to the location after the extra field
345
347
#endif
346
348
}
347
349
@@ -358,7 +360,7 @@ void memory::deallocate(void * p) {
358
360
size_t sz = malloc_usable_size (p);
359
361
void * real_p = p;
360
362
#else
361
- size_t * sz_p = reinterpret_cast <size_t *>(p) - 1 ;
363
+ size_t * sz_p = reinterpret_cast <size_t *>(p) - SIZE_T_ALIGN ;
362
364
size_t sz = *sz_p;
363
365
void * real_p = reinterpret_cast <void *>(sz_p);
364
366
#endif
@@ -368,7 +370,7 @@ void memory::deallocate(void * p) {
368
370
369
371
void * memory::allocate (size_t s) {
370
372
#ifndef HAS_MALLOC_USABLE_SIZE
371
- s = s + sizeof (size_t ); // we allocate an extra field!
373
+ s = s + SIZE_T_ALIGN * sizeof (size_t ); // we allocate an extra field!
372
374
#endif
373
375
g_memory_alloc_size += s;
374
376
g_memory_alloc_count += 1 ;
@@ -389,7 +391,7 @@ void * memory::allocate(size_t s) {
389
391
return r;
390
392
#else
391
393
*(static_cast <size_t *>(r)) = s;
392
- return static_cast <size_t *>(r) + 1 ; // we return a pointer to the location after the extra field
394
+ return static_cast <size_t *>(r) + SIZE_T_ALIGN ; // we return a pointer to the location after the extra field
393
395
#endif
394
396
}
395
397
@@ -401,10 +403,10 @@ void* memory::reallocate(void *p, size_t s) {
401
403
if (sz >= s)
402
404
return p;
403
405
#else
404
- size_t * sz_p = reinterpret_cast <size_t *>(p) - 1 ;
406
+ size_t * sz_p = reinterpret_cast <size_t *>(p) - SIZE_T_ALIGN ;
405
407
size_t sz = *sz_p;
406
408
void * real_p = reinterpret_cast <void *>(sz_p);
407
- s = s + sizeof (size_t ); // we allocate an extra field!
409
+ s = s + SIZE_T_ALIGN * sizeof (size_t ); // we allocate an extra field!
408
410
#endif
409
411
g_memory_alloc_size += s - sz;
410
412
g_memory_alloc_count += 1 ;
@@ -425,7 +427,7 @@ void* memory::reallocate(void *p, size_t s) {
425
427
return r;
426
428
#else
427
429
*(static_cast <size_t *>(r)) = s;
428
- return static_cast <size_t *>(r) + 1 ; // we return a pointer to the location after the extra field
430
+ return static_cast <size_t *>(r) + SIZE_T_ALIGN ; // we return a pointer to the location after the extra field
429
431
#endif
430
432
}
431
433
0 commit comments