×

Search anything:

bli_malloc_user [explained with C++ code]

C++

Internship at OpenGenus

Get this book -> Problems on Array: For Interviews and Competitive Programming

In this article at OpenGenus, we have explored bli_malloc_user in depth. bli_malloc_user() is a memory allocation API available in BLIS, a library.

Table of contents:

  1. What is bli_malloc_user?
  2. bli_malloc_user in BLIS

What is bli_malloc_user?

bli_malloc_user is a library method in BLIS/ BLAS to allocate memory. It is a wrapper function around malloc(). bli_malloc_user provides error checking and handling which is not available in malloc(). bli_malloc_user() is extensively used within the BLIS library for memory allocation.

Following is a C++ code snippet for using bli_malloc_user:

#include <blis/blis.h>

int main() {
    // Allocate a buffer of size 1024 bytes
    void* buffer = bli_malloc_user(1024);
    // Use the buffer
    // add code ...
    // Free the buffer
    bli_free_user(buffer);
    return 0;
}

bli_malloc_user in BLIS

In BLIS variants, it is implemented in file blis/frame/base/bli_malloc.c where other malloc variants are available as well.

bli_malloc_user() is used to allocate aligned dynamic memory. It uses bli_fmalloc_align() internally which is a variant.

The implementation of bli_malloc_user() is as follows:

void* bli_malloc_user( size_t size, err_t* r_val )
{
	const malloc_ft malloc_fp  = BLIS_MALLOC_USER;
	const size_t    align_size = BLIS_HEAP_ADDR_ALIGN_SIZE;

	#ifdef BLIS_ENABLE_MEM_TRACING
	printf( "bli_malloc_user(): size %ld, align size %ld\n",
	        ( long )size, ( long )align_size );
	fflush( stdout );
	#endif

	void* p = bli_fmalloc_align( malloc_fp, size, align_size, r_val );

	return p;
}

With this article at OpenGenus, you must have the complete idea of bli_malloc_user.

bli_malloc_user [explained with C++ code]
Share this