Changeset 7df201c for libcfa


Ignore:
Timestamp:
Sep 27, 2019, 2:44:37 PM (5 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
a094f13
Parents:
70b4ea20
Message:

add 3 new alloc routines to safely bulk initialize storage

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/stdlib.hfa

    r70b4ea20 r7df201c  
    1010// Created On       : Thu Jan 28 17:12:35 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jul 23 14:14:59 2019
    13 // Update Count     : 373
     12// Last Modified On : Fri Sep 27 12:09:18 2019
     13// Update Count     : 381
    1414//
    1515
     
    8181        } // alloc
    8282
     83        T * alloc( T & fill ) {
     84                return (T *)memcpy( (T *)alloc(), &fill, sizeof(T) ); // initialize with fill value
     85        } // alloc
     86
    8387        T * alloc( size_t dim ) {
    8488                if ( _Alignof(T) <= libAlign() ) return (T *)(void *)malloc( dim * (size_t)sizeof(T) ); // C malloc
     
    8892        T * alloc( size_t dim, char fill ) {
    8993                return (T *)memset( (T *)alloc( dim ), (int)fill, dim * sizeof(T) ); // initialize with fill value
     94        } // alloc
     95
     96        T * alloc( size_t dim, T & fill ) {
     97                T * r = (T *)alloc( dim );
     98                for ( i; dim ) { memcpy( &r[i], &fill, sizeof(T) ); } // initialize with fill value
     99                return r;
     100        } // alloc
     101
     102        T * alloc( size_t dim, T fill[] ) {
     103                return (T *)memcpy( (T *)alloc( dim ), fill, dim * sizeof(T) ); // initialize with fill value
    90104        } // alloc
    91105
Note: See TracChangeset for help on using the changeset viewer.