473,602 Members | 2,751 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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<DataTyp eas 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 (...).AddrOfPin nedObject().ToP ointer() 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<typenam e DataTypepublic ref class RingBuffer
{
array<DataType^ m_Buffer;
DataType *m_Buffer_Ptr; // Error
}

Jan 24 '07 #1
1 3423

"interX" <TK***@gmx.dewr ote in message
news:11******** **************@ s48g2000cws.goo glegroups.com.. .
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
Generics are required to support all possible data types with the same
MSIL.... this isn't possible for what you are trying to do. Probably you
want a template instead.
>
Is there a posible way to get a this unmanaged pointer? My problem is
that it isn't allowed to creat a pin_ptr<DataTyp eas a class member
and it takes quite a while to do it every function call. Or, do I I
Probably you need to find a way to do what you want without pinning... so
much pinning is bad for performance, and trying to pin long-term is even
worse.
realy have to do a hack and creat a void* from the array by using
GCHandle::Alloc (...).AddrOfPin nedObject().ToP ointer() and then cast it
to a byte* and shift it each time by sizeof(DataType )?
sizeof (DataType) isn't known for a generic parameter, so neither you nor
the C++ compiler can do pointer arithmetic. Only managed arrays contain the
extra information necessary to reference individual elements.
>
By the way, my generic typs are never reference objects, only value
structs and data types like int, byte, ... .
But an array is a managed type in .NET, and the garbage collector will move
it around.

Furthermore, even without using pointers, you'll find that generics are
totally useless with value types for doing anything more than containment,
because they don't implement much in the way of interfaces, any sort of math
is totally out of the question.
>
Thanks for any help!

Thorsten

generic<typenam e DataTypepublic ref class RingBuffer
{
array<DataType^ m_Buffer;
DataType *m_Buffer_Ptr; // Error
interior_ptr<Da taType*might work... but still won't be pinned, and still
couldn't allow pointer arithmetic, because sizeof () isn't known, so I think
the compiler will still forbid it.
}

Jan 24 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
4380
by: Simon | last post by:
I'm a js newbie trying to use some very simple js to call an ActiveX object's methods. I need to use a pointer to call an embedded ActiveX object's method to receive a number. As I understand it, js is typeless so how can I get a variable to be a pointer type? Passing var i as the parameter gets an undefined value in return. Thanks IA, Simon
52
5620
by: Douglas Garstang | last post by:
I can't believe I've been trying to work this out for hours now, and I can't believe I couldn't find someone asking for a similar solution in the newsgroups. No wonder I hate C so much, and every time I get the textbooks out end up throwing them against the wall in rage. Thats been going on for 10 years now. Anyway, I have: typedef struct _record { int age;
9
5285
by: Juggernaut | last post by:
I am trying to create a p_thread pthread_create(&threads, &attr, Teste, (void *)var); where var is a char variable. But this doesnt't work, I get this message: test.c:58: warning: cast to pointer from integer of different size. Now I thought that when it was a void I could pass anything? Thing is it works when I use an int, but in this case I wanted to use a char. It wouldnt be hard to work around it, but it annoys me because I've heard...
16
2286
by: junky_fellow | last post by:
According to Section A6.6 Pointers and Integers (k & R) " A pointer to one type may be converted to a pointer to another type. The resulting pointer may cause addressing exceptions if the subject pointer does not refer to an object suitably aligned in storage. It is guaranteed that a pointer to an object may be converted to a pointer to an object whose type requires less or equally strict storage alignment and back again without change;...
49
2772
by: elmar | last post by:
Hi Clers, If I look at my ~200000 lines of C code programmed over the past 15 years, there is one annoying thing in this smart language, which somehow reduces the 'beauty' of the source code ;-): char *cp; void *vp; void **vpp;
7
3382
by: juerg.lemke | last post by:
Hi everyone I am interested in having multiple functions with different prototypes and deciding, by setting a pointer, which of them to use later in the program. Eg: int f1(void); char* f2(int);
2
2921
by: domehead100 | last post by:
I have a templated class, CDerived: template <typename TValue, typename TDraw, typename TEdit ...> class CDerived : public CBase { TValue m_Value public: TValue& GetValue() const {
1
1779
by: pekbob1 | last post by:
Hi Everybody I have the error (ObjectDataSource 'ObjectDataSource1' could not find a non-generic method 'UpdatePre' that has parameters: Comp, Job_Number, Request_Date, Customer, Contact_Name, Tel, Email, Media, Job_Size, Colors, Number_of_Lots, Proof, Job_Detail, PrepressID) when I tried to update the values in my dataset. (before I had the problem to Insert and Delete and I changed OldValuesParameterFormatString="original_{0}" to...
50
4459
by: Juha Nieminen | last post by:
I asked a long time ago in this group how to make a smart pointer which works with incomplete types. I got this answer (only relevant parts included): //------------------------------------------------------------------ template<typename Data_t> class SmartPointer { Data_t* data; void(*deleterFunc)(Data_t*);
0
7993
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7920
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8268
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6730
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
3900
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3944
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2418
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1510
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1254
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.