Pointer to a generic type parameter



Hi

I'm new in VC++ and have a question to generics. I have a generic
class, which contains an array of the generic type. This array I can
pin and then I would like to get an unmanaged pointer to it. Therefore
I wanted to creat a class member which represents the pointer to the
array. Unfortunately I get the folowring compile error for the code
beneath:

error C3229: 'DataType *' : indirections on a generic type parameter
are not allowed

Is there a posible way to get a this unmanaged pointer? My problem is
that it isn't allowed to creat a pin_ptr<DataType> as a class member
and it takes quite a while to do it every function call. Or, do I I
realy have to do a hack and creat a void* from the array by using
GCHandle::Alloc(...).AddrOfPinnedObject().ToPointer() and then cast it
to a byte* and shift it each time by sizeof(DataType)?

By the way, my generic typs are never reference objects, only value
structs and data types like int, byte, ... .

Thanks for any help!

Thorsten



generic<typename DataType> public ref class RingBuffer
{
array<DataType> ^m_Buffer;
DataType *m_Buffer_Ptr; // Error
}

.



Relevant Pages

  • Wasted Efforts (Parametric polymorphism?)
    ... And even if below solves problems that are solved in generics or templates, does that necessarily mean that we can't come up with a better solution.. ... astrarray = array of string; ... procedure add(const item: AnyType var arr: AnyTypeArray); ...
    (borland.public.delphi.non-technical)
  • Re: Announcing CodeGear RAD Studio 2007
    ... genuine quest to determine where generics can be useful outside of the ... oft quoted example of type safe containers. ... if generics may be useful. ... How about an array copier? ...
    (borland.public.delphi.non-technical)
  • Re: A question related to type casting
    ... Given that the distinction already had to be worked around (you couldn't put an int in a List before Java 5), the added complexity would end up being rather pointless. ... Lack of support for value types means more than just the execution overhead of the boxing. ... For example, ArrayList<T> stores the elements in an array of type T. But, there's no way for the class to use an array of ints; it has to be Integer, with each array element a reference to a boxed int, and of course for there to be a separately allocated Integer instance for each non-null array element. ... You're correct that it would have been more complex to support generics in a reifiable way. ...
    (comp.lang.java.programmer)
  • Re: Generic procedures and their parameters
    ... Integer belong to Ordered'Class. ... It's a shaky ground. ... array types based on exactly same combination of index and element types. ... coincidence that "other languages" drift towards supporting generics, ...
    (comp.lang.ada)
  • Re: generics and arrays and multi-class collections
    ... java.util.ArrayList uses an array of Object to store its ... The cast generates an unchecked warning. ... Wisdome is "use Java generics only at its shallowest". ...
    (comp.lang.java.programmer)