Actions

icon Post
text/html Subscribe
text/html Unsubscribe

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Subject: Re: [vsipl++] proposal: a typed alloc_align()
  • From: Jules Bergmann <jules@xxxxxxxxxxxxxxxx>
  • Date: Thu, 03 Nov 2005 07:16:40 -0500

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