Changeset cfbc703d for libcfa/src/stdlib.cfa
- Timestamp:
- Apr 1, 2020, 9:32:21 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 6d43cdde
- Parents:
- 5137f9f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/stdlib.cfa
r5137f9f rcfbc703d 10 10 // Created On : Thu Jan 28 17:10:29 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Feb 4 08:27:08202013 // Update Count : 4 8612 // Last Modified On : Tue Mar 31 13:26:46 2020 13 // Update Count : 495 14 14 // 15 15 … … 20 20 #define _XOPEN_SOURCE 600 // posix_memalign, *rand48 21 21 #include <string.h> // memcpy, memset 22 #include <malloc.h> // malloc_usable_size23 22 //#include <math.h> // fabsf, fabs, fabsl 24 23 #include <complex.h> // _Complex_I … … 38 37 } // alloc_set 39 38 39 T * alloc_set( T ptr[], size_t dim, T fill ) { // realloc array with fill 40 size_t olen = malloc_usable_size( ptr ); // current allocation 41 void * nptr = (void *)realloc( (void *)ptr, dim * sizeof(T) ); // C realloc 42 size_t nlen = malloc_usable_size( nptr ); // new allocation 43 if ( nlen > olen ) { // larger ? 44 for ( i; dim ) { memcpy( &ptr[i], &fill, sizeof(T) ); } // initialize with fill value 45 } // if 46 return (T *)nptr; 47 } // alloc_align_set 48 40 49 T * alloc_align_set( T ptr[], size_t align, char fill ) { // aligned realloc with fill 41 50 size_t olen = malloc_usable_size( ptr ); // current allocation … … 45 54 if ( nlen > olen ) { // larger ? 46 55 memset( (char *)nptr + olen, (int)fill, nlen - olen ); // initialize added storage 56 } // if 57 return (T *)nptr; 58 } // alloc_align_set 59 60 T * alloc_align_set( T ptr[], size_t align, size_t dim, T fill ) { // aligned realloc with fill 61 size_t olen = malloc_usable_size( ptr ); // current allocation 62 void * nptr = (void *)realloc( (void *)ptr, align, sizeof(T) ); // CFA realloc 63 // char * nptr = alloc_align( ptr, align ); 64 size_t nlen = malloc_usable_size( nptr ); // new allocation 65 if ( nlen > olen ) { // larger ? 66 for ( i; dim ) { memcpy( &ptr[i], &fill, sizeof(T) ); } // initialize with fill value 47 67 } // if 48 68 return (T *)nptr;
Note: See TracChangeset
for help on using the changeset viewer.