Пример #1
0
AA_API void *aa_mem_region_tmprealloc( aa_mem_region_t *region, size_t size )
{
    void *old_ptr = region->head;
    size_t old_size = (size_t)(region->node->end - region->head);
    void *new_ptr = aa_mem_region_tmpalloc(region, size);

    if( old_ptr != new_ptr ) {
        memcpy( new_ptr, old_ptr, old_size );
    }

    return new_ptr;
}
Пример #2
0
char* aa_mem_region_vprintf(aa_mem_region_t *reg, const char *fmt, va_list ap ) {
    int r;
    do {
        va_list ap1;
        va_copy(ap1, ap);
        // r is one less than needed buffer size, (doesn't count '\0')
        r = vsnprintf((char*)aa_mem_region_ptr(reg), aa_mem_region_freesize(reg),
                      fmt, ap1);
        va_end(ap1);
    }while( (r >= (int)aa_mem_region_freesize(reg) ) &&
            aa_mem_region_tmpalloc( reg, (size_t)r + 1) );
    return (char*)aa_mem_region_alloc(reg,(size_t)r + 1);
}
Пример #3
0
size_t aa_io_fread_matrix_fix( FILE *fin, size_t m, size_t n,
                               double *A, size_t lda )
{
    struct aa_mem_region *reg = aa_mem_region_local_get();
    void *ptr = aa_mem_region_tmpalloc(reg,1);

    size_t cnt = 0;
    for( size_t i = 0; i < m; i ++ ) {
        cnt += aa_io_getvector( fin, reg,
                                n, &AA_MATREF(A, lda, i, 0), lda );
    }

    aa_mem_region_pop( reg, ptr );

    return cnt;
}
Пример #4
0
void *aa_mem_region_local_tmpalloc(size_t size) {
    return aa_mem_region_tmpalloc( aa_mem_region_local_get(), size );
}