Changeset e310238
- Timestamp:
- Jul 19, 2020, 8:53:19 PM (5 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:
- b89c7c2
- Parents:
- 849fb370
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/stdlib.cfa
r849fb370 re310238 9 9 // Author : Peter A. Buhr 10 10 // Created On : Thu Jan 28 17:10:29 2016 11 // Last Modified By : Andrew Beach12 // Last Modified On : Tue Jun 2 16:46:00202013 // Update Count : 50 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Jul 19 15:05:28 2020 13 // Update Count : 501 14 14 // 15 15 … … 25 25 26 26 //--------------------------------------- 27 28 forall( dtype T | sized(T) ) {29 T * alloc_set( T ptr[], size_t dim, char fill ) { // realloc array with fill30 size_t olen = malloc_usable_size( ptr ); // current allocation31 void * nptr = (void *)realloc( (void *)ptr, dim * sizeof(T) ); // C realloc32 size_t nlen = malloc_usable_size( nptr ); // new allocation33 if ( nlen > olen ) { // larger ?34 memset( (char *)nptr + olen, (int)fill, nlen - olen ); // initialize added storage35 } // if36 return (T *)nptr;37 } // alloc_set38 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 T * alloc_align_set( T ptr[], size_t align, char fill ) { // aligned realloc with fill52 size_t olen = malloc_usable_size( ptr ); // current allocation53 void * nptr = (void *)realloc( (void *)ptr, align, sizeof(T) ); // CFA realloc54 // char * nptr = alloc_align( ptr, align );55 size_t nlen = malloc_usable_size( nptr ); // new allocation56 if ( nlen > olen ) { // larger ?57 memset( (char *)nptr + olen, (int)fill, nlen - olen ); // initialize added storage58 } // if59 return (T *)nptr;60 } // alloc_align_set61 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 } // distribution73 27 74 28 // allocation/deallocation and constructor/destructor, non-array types
Note: See TracChangeset
for help on using the changeset viewer.