- Timestamp:
- Jul 23, 2020, 1:33:57 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:
- e262b5e, f854ee32
- Parents:
- 5751a56 (diff), f19fbbc (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- libcfa/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/heap.cfa
r5751a56 r54eb5ebd 10 10 // Created On : Tue Dec 19 21:58:35 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Jul 19 17:37:21202013 // Update Count : 80 612 // Last Modified On : Mon Jul 20 23:00:32 2020 13 // Update Count : 808 14 14 // 15 15 … … 901 901 if ( oalign == 0 && size <= odsize && odsize <= size * 2 ) { // allow 50% wasted storage for smaller size 902 902 header->kind.real.blockSize &= -2; // no alignment and turn off 0 fill 903 if ( size != odsize ) header->kind.real.size = size; // reset allocation size 903 904 return oaddr; 904 905 } // if … … 929 930 930 931 size_t odsize = dataStorage( bsize, oaddr, header ); // data storage available in bucket 931 if ( size <= odsize && odsize <= size * 2 ) { // allow up to 50% wasted storage in smaller size 932 // Do not know size of original allocation => cannot do 0 fill for any additional space because do not know 933 // where to start filling, i.e., do not overwrite existing values in space. 932 if ( size <= odsize && odsize <= size * 2 ) { // allow up to 50% wasted storage in smaller size 933 if ( size != odsize ) header->kind.real.size = size; // reset allocation size 934 934 return oaddr; 935 935 } // if … … 1227 1227 if ( size <= odsize && odsize <= size * 2 ) { // allow 50% wasted storage for smaller size 1228 1228 header->kind.real.blockSize &= -2; // turn off 0 fill 1229 if ( size != odsize ) header->kind.real.size = size; // reset allocation size 1229 1230 return oaddr; 1230 1231 } // if -
libcfa/src/heap.hfa
r5751a56 r54eb5ebd 10 10 // Created On : Tue May 26 11:23:55 2020 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Ju n 1 21:19:00202013 // Update Count : 1 012 // Last Modified On : Mon Jul 20 18:52:31 2020 13 // Update Count : 11 14 14 // 15 15 … … 35 35 void * resize( void * oaddr, size_t size ); 36 36 void * amemalign( size_t align, size_t dim, size_t elemSize ); 37 void * cmemalign( size_t align, size_t noOfElems, size_t elemSize );37 void * cmemalign( size_t align, size_t dim, size_t elemSize ); 38 38 size_t malloc_alignment( void * addr ); 39 39 bool malloc_zero_fill( void * addr ); -
libcfa/src/stdlib.hfa
r5751a56 r54eb5ebd 10 10 // Created On : Thu Jan 28 17:12:35 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jul 20 14:29:21202013 // Update Count : 4 6412 // Last Modified On : Tue Jul 21 07:58:05 2020 13 // Update Count : 475 14 14 // 15 15 … … 39 39 //--------------------------------------- 40 40 41 // Macro because of returns 42 #define $VAR_ALLOC( allocation, alignment ) \ 43 if ( _Alignof(T) <= libAlign() ) return (T *)(void *)allocation( (size_t)sizeof(T) ); /* C allocation */ \ 44 else return (T *)alignment( _Alignof(T), sizeof(T) ) 45 46 #define $ARRAY_ALLOC( allocation, alignment, dim ) \ 47 if ( _Alignof(T) <= libAlign() ) return (T *)(void *)allocation( dim, (size_t)sizeof(T) ); /* C allocation */ \ 48 else return (T *)alignment( _Alignof(T), dim, sizeof(T) ) 49 50 #define $RE_SPECIALS( ptr, size, allocation, alignment ) \ 51 if ( unlikely( size == 0 ) || unlikely( ptr == 0p ) ) { \ 52 if ( unlikely( size == 0 ) ) free( ptr ); \ 53 $VAR_ALLOC( malloc, memalign ); \ 54 } /* if */ 55 41 56 static inline forall( dtype T | sized(T) ) { 42 57 // Cforall safe equivalents, i.e., implicit size specification 43 58 44 59 T * malloc( void ) { 45 if ( _Alignof(T) <= libAlign() ) return (T *)(void *)malloc( (size_t)sizeof(T) ); // C malloc 46 else return (T *)memalign( _Alignof(T), sizeof(T) ); 60 $VAR_ALLOC( malloc, memalign ); 47 61 } // malloc 48 62 49 63 T * aalloc( size_t dim ) { 50 if ( _Alignof(T) <= libAlign() ) return (T *)(void *)aalloc( dim, (size_t)sizeof(T) ); // CFA aalloc 51 else return (T *)amemalign( _Alignof(T), dim, sizeof(T) ); 64 $ARRAY_ALLOC( aalloc, amemalign, dim ); 52 65 } // aalloc 53 66 54 67 T * calloc( size_t dim ) { 55 if ( _Alignof(T) <= libAlign() )return (T *)(void *)calloc( dim, sizeof(T) ); // C calloc 56 else return (T *)cmemalign( _Alignof(T), dim, sizeof(T) ); 68 $ARRAY_ALLOC( calloc, cmemalign, dim ); 57 69 } // calloc 58 70 59 71 T * resize( T * ptr, size_t size ) { // CFA resize, eliminate return-type cast 60 if ( unlikely( size == 0 ) || unlikely( ptr == 0p ) ) { // special cases 61 if ( unlikely( size == 0 ) ) free( ptr ); 62 if ( _Alignof(T) <= libAlign() ) return (T *)(void *)malloc( size ); // C malloc 63 else return (T *)memalign( _Alignof(T), size ); // C memalign 64 } // if 72 $RE_SPECIALS( ptr, size, malloc, memalign ); 65 73 return (T *)(void *)resize( (void *)ptr, size ); // CFA resize 66 74 } // resize 67 75 68 76 T * realloc( T * ptr, size_t size ) { // CFA realloc, eliminate return-type cast 69 if ( unlikely( size == 0 ) || unlikely( ptr == 0p ) ) { // special cases 70 if ( unlikely( size == 0 ) ) free( ptr ); 71 if ( _Alignof(T) <= libAlign() ) return (T *)(void *)malloc( size ); // C malloc 72 else return (T *)memalign( _Alignof(T), size ); // C memalign 73 } // if 77 $RE_SPECIALS( ptr, size, malloc, memalign ); 74 78 return (T *)(void *)realloc( (void *)ptr, size ); // C realloc 75 79 } // realloc … … 159 163 T * alloc_set( T ptr[], size_t dim, char fill ) { // realloc array with fill 160 164 size_t osize = malloc_size( ptr ); // current allocation 161 T * nptr = realloc( ptr, dim * sizeof(T) ); // CFA realloc162 size_t nsize = malloc_size( nptr ); // new allocation165 size_t nsize = dim * sizeof(T); // new allocation 166 T * nptr = realloc( ptr, nsize ); // CFA realloc 163 167 if ( nsize > osize ) { // larger ? 164 168 memset( (char *)nptr + osize, (int)fill, nsize - osize ); // initialize added storage … … 168 172 169 173 T * alloc_set( T ptr[], size_t dim, T & fill ) { // realloc array with fill 170 size_t odim = malloc_size( ptr ) / sizeof(T); // current allocation 171 T * nptr = realloc( ptr, dim * sizeof(T) ); // CFA realloc 172 size_t ndim = malloc_size( nptr ) / sizeof(T); // new allocation 174 size_t odim = malloc_size( ptr ) / sizeof(T); // current dimension 175 size_t nsize = dim * sizeof(T); // new allocation 176 size_t ndim = nsize / sizeof(T); // new dimension 177 T * nptr = realloc( ptr, nsize ); // CFA realloc 173 178 if ( ndim > odim ) { // larger ? 174 179 for ( i; odim ~ ndim ) { … … 226 231 T * alloc_align_set( T ptr[], size_t align, size_t dim, char fill ) { 227 232 size_t osize = malloc_size( ptr ); // current allocation 228 T * nptr = realloc( ptr, align, dim * sizeof(T) ); // CFA realloc229 size_t nsize = malloc_size( nptr ); // new allocation233 size_t nsize = dim * sizeof(T); // new allocation 234 T * nptr = realloc( ptr, align, nsize ); // CFA realloc 230 235 if ( nsize > osize ) { // larger ? 231 236 memset( (char *)nptr + osize, (int)fill, nsize - osize ); // initialize added storage … … 235 240 236 241 T * alloc_align_set( T ptr[], size_t align, size_t dim, T & fill ) { 237 size_t odim = malloc_size( ptr ) / sizeof(T); // current allocation 238 T * nptr = realloc( ptr, align, dim * sizeof(T) ); // CFA realloc 239 size_t ndim = malloc_size( nptr ); // new allocation 242 size_t odim = malloc_size( ptr ) / sizeof(T); // current dimension 243 size_t nsize = dim * sizeof(T); // new allocation 244 size_t ndim = nsize / sizeof(T); // new dimension 245 T * nptr = realloc( ptr, align, nsize ); // CFA realloc 240 246 if ( ndim > odim ) { // larger ? 241 247 for ( i; odim ~ ndim ) {
Note: See TracChangeset
for help on using the changeset viewer.