Changes in libcfa/src/stdlib.cfa [76e2113:e3fea42]
- File:
-
- 1 edited
-
libcfa/src/stdlib.cfa (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/stdlib.cfa
r76e2113 re3fea42 10 10 // Created On : Thu Jan 28 17:10:29 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T hu Apr 16 22:43:33202013 // Update Count : 4 9812 // Last Modified On : Tue Feb 4 08:27:08 2020 13 // Update Count : 486 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_size 22 23 //#include <math.h> // fabsf, fabs, fabsl 23 24 #include <complex.h> // _Complex_I … … 37 38 } // alloc_set 38 39 39 T * alloc_set( T ptr[], size_t dim, T fill ) { // realloc array with fill40 size_t olen = malloc_usable_size( ptr ); // current allocation41 void * nptr = (void *)realloc( (void *)ptr, dim * sizeof(T) ); // C realloc42 size_t nlen = malloc_usable_size( nptr ); // new allocation43 if ( nlen > olen ) { // larger ?44 for ( i; malloc_size( ptr ) / sizeof(T) ~ dim ) {45 memcpy( &ptr[i], &fill, sizeof(T) ); // initialize with fill value46 } // for47 } // if48 return (T *)nptr;49 } // alloc_align_set50 51 40 T * alloc_align_set( T ptr[], size_t align, char fill ) { // aligned realloc with fill 52 41 size_t olen = malloc_usable_size( ptr ); // current allocation … … 59 48 return (T *)nptr; 60 49 } // alloc_align_set 61 62 T * alloc_align_set( T ptr[], size_t align, size_t dim, T fill ) { // aligned realloc with fill63 size_t olen = malloc_usable_size( ptr ); // current allocation64 void * nptr = (void *)realloc( (void *)ptr, align, sizeof(T) ); // CFA realloc65 // char * nptr = alloc_align( ptr, align );66 size_t nlen = malloc_usable_size( nptr ); // new allocation67 if ( nlen > olen ) { // larger ?68 for ( i; dim ) { memcpy( &ptr[i], &fill, sizeof(T) ); } // initialize with fill value69 } // if70 return (T *)nptr;71 } // alloc_align_set72 50 } // distribution 73 51
Note:
See TracChangeset
for help on using the changeset viewer.