Changes in libcfa/src/stdlib.cfa [e3fea42:76e2113]
- File:
-
- 1 edited
-
libcfa/src/stdlib.cfa (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/stdlib.cfa
re3fea42 r76e2113 10 10 // Created On : Thu Jan 28 17:10:29 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T ue Feb 4 08:27:08202013 // Update Count : 4 8612 // Last Modified On : Thu Apr 16 22:43:33 2020 13 // Update Count : 498 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; malloc_size( ptr ) / sizeof(T) ~ dim ) { 45 memcpy( &ptr[i], &fill, sizeof(T) ); // initialize with fill value 46 } // for 47 } // if 48 return (T *)nptr; 49 } // alloc_align_set 50 40 51 T * alloc_align_set( T ptr[], size_t align, char fill ) { // aligned realloc with fill 41 52 size_t olen = malloc_usable_size( ptr ); // current allocation … … 45 56 if ( nlen > olen ) { // larger ? 46 57 memset( (char *)nptr + olen, (int)fill, nlen - olen ); // initialize added storage 58 } // if 59 return (T *)nptr; 60 } // alloc_align_set 61 62 T * alloc_align_set( T ptr[], size_t align, size_t dim, T fill ) { // aligned realloc with fill 63 size_t olen = malloc_usable_size( ptr ); // current allocation 64 void * nptr = (void *)realloc( (void *)ptr, align, sizeof(T) ); // CFA realloc 65 // char * nptr = alloc_align( ptr, align ); 66 size_t nlen = malloc_usable_size( nptr ); // new allocation 67 if ( nlen > olen ) { // larger ? 68 for ( i; dim ) { memcpy( &ptr[i], &fill, sizeof(T) ); } // initialize with fill value 47 69 } // if 48 70 return (T *)nptr;
Note:
See TracChangeset
for help on using the changeset viewer.