[vsipl++] proposal: a typed alloc_align()

Jules Bergmann jules at codesourcery.com
Thu Nov 3 12:16:40 UTC 2005


Stefan,

This sounds good.

We could also move the 'sizeof(T)' scaling into the alloc_align as well 
(requested sizes are usually 'number of elements x sizeof(T)').

Given this, should the template parameter be the type being allocated, 
or a the type of the resulting pointer?  I.e.

	float* foo = alloc_align<float*>(align, elem*sizeof(T));

or

	float* foo = alloc_align<float>(align, elem);

I vote for the second.

				-- Jules

Stefan Seefeld wrote:
> I'v seen expressions such as
> 
> foo = static_cast<some_type>(alloc_align(align, size));
> 
> a lot recently, and I wonder whether this could be tidied up a bit by 
> parametrizing
> alloc_align (i.e. internalizing the static_cast):
> 
> template <typename R>
> inline
> R
> alloc_align(size_t align, size_t size)
> {
>   return static_cast<R>(alloc_align(align, size));

perhaps:

     return static_cast<R*>(alloc_align(align, size*sizeof(R));

> }
> 
> and then be able to write
> 
> foo = alloc_align<some_type>(align, size);
> 
> That avoids users of alloc_align being exposed to void *.
> 
> Thoughts ?
> 
> Regards,
>         Stefan



More information about the vsipl++ mailing list