gmio_core: add "default gmio_buffer constructor function"
This commit is contained in:
parent
7fc0836c2b
commit
692c2d7f58
@ -85,3 +85,28 @@ void gmio_buffer_deallocate(gmio_buffer_t *buffer)
|
|||||||
if (buffer != NULL && buffer->deallocate_func != NULL)
|
if (buffer != NULL && buffer->deallocate_func != NULL)
|
||||||
buffer->deallocate_func(buffer->ptr);
|
buffer->deallocate_func(buffer->ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gmio_buffer_t gmio_buffer_default_internal_ctor()
|
||||||
|
{
|
||||||
|
return gmio_buffer_malloc(128 * 1024); /* 128 KB */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Warning: global variable ... */
|
||||||
|
static gmio_buffer_constructor_func_t gmio_global_buffer_ctor =
|
||||||
|
gmio_buffer_default_internal_ctor;
|
||||||
|
|
||||||
|
void gmio_buffer_set_default_constructor(gmio_buffer_constructor_func_t ctor)
|
||||||
|
{
|
||||||
|
if (ctor != NULL)
|
||||||
|
gmio_global_buffer_ctor = ctor;
|
||||||
|
}
|
||||||
|
|
||||||
|
gmio_buffer_constructor_func_t gmio_buffer_default_constructor()
|
||||||
|
{
|
||||||
|
return gmio_global_buffer_ctor;
|
||||||
|
}
|
||||||
|
|
||||||
|
gmio_buffer_t gmio_buffer_default()
|
||||||
|
{
|
||||||
|
return gmio_global_buffer_ctor();
|
||||||
|
}
|
||||||
|
@ -63,6 +63,33 @@ GMIO_LIB_EXPORT gmio_buffer_t gmio_buffer_alloca(size_t size);
|
|||||||
/*! Safe and convenient call to gmio_buffer::deallocate_func() */
|
/*! Safe and convenient call to gmio_buffer::deallocate_func() */
|
||||||
GMIO_LIB_EXPORT void gmio_buffer_deallocate(gmio_buffer_t* buffer);
|
GMIO_LIB_EXPORT void gmio_buffer_deallocate(gmio_buffer_t* buffer);
|
||||||
|
|
||||||
|
/*! Typedef for a pointer to a function that creates an allocated buffer
|
||||||
|
*
|
||||||
|
* Signature:
|
||||||
|
* \code gmio_buffer_t buffer_ctor(); \endcode
|
||||||
|
*/
|
||||||
|
typedef gmio_buffer_t (*gmio_buffer_constructor_func_t)();
|
||||||
|
|
||||||
|
/*! Installs a global function to construct gmio_buffer objects
|
||||||
|
*
|
||||||
|
* The constructor function allocates a gmio_buffer object on demand, to be
|
||||||
|
* used when a temporary buffer is needed.
|
||||||
|
*
|
||||||
|
* This function is not thread-safe.
|
||||||
|
*/
|
||||||
|
GMIO_LIB_EXPORT void gmio_buffer_set_default_constructor(
|
||||||
|
gmio_buffer_constructor_func_t ctor);
|
||||||
|
|
||||||
|
/*! Returns the currently installed function to construct gmio_buffer objects
|
||||||
|
*
|
||||||
|
* It is initialized to <tt>gmio_buffer_malloc(128KB)</tt>
|
||||||
|
*/
|
||||||
|
GMIO_LIB_EXPORT gmio_buffer_constructor_func_t gmio_buffer_default_constructor();
|
||||||
|
|
||||||
|
/*! Returns a gmio_buffer object created using the function
|
||||||
|
* gmio_buffer_default_constructor() */
|
||||||
|
GMIO_LIB_EXPORT gmio_buffer_t gmio_buffer_default();
|
||||||
|
|
||||||
GMIO_C_LINKAGE_END
|
GMIO_C_LINKAGE_END
|
||||||
|
|
||||||
#endif /* GMIO_BUFFER_H */
|
#endif /* GMIO_BUFFER_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user