473,800 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

fixed address of struct constrained template

Hi,
I have many suitable structures wich I need to handle in a binary fashion,
I can take the address of a struct inside unsafe and fixed block
and this works when the struct is pased as a ref parameter,

however if I use a template this breaks, despite restraining it to struct.
public void Copy(ref datahead_struct src)
{
unsafe
{
fixed (void* p = &src)
{
//...
}
}
}
public void Copy<T>(ref T src) where T:struct
{
unsafe
{
fixed (void* p = &src)
{
// ^ ...Error 1 Cannot take the address of, get the size of, or declare a
pointer to a managed type ('T')
}
}
}

I am wondering if this is because it cant know if the structure contains
managed object references,
however I dont want to copy and paste the same function for every struct
I have :s

any ideas how i can get the address of a struct that isnt insanly unsafe ?

I know there are methods wich involve quite a lot of copying but this is
precisly what im trying to avoid.

many thanks
Colin =^.^=
Jun 27 '08 #1
0 904

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

Similar topics

3
5837
by: Cgacc20 | last post by:
I have a c struct from old code that cannot be modified and I am trying to write a wrapper C++ class around it. This class is often passed as a pointer to some c functions of a library and I wanted to keep my new class transparent and compatible with those functions. That is, when using the code, I should be able to do either: oldVector xyz; function( &xyz ); myVector xyz; function( &xyz );
2
2093
by: Domenico Andreoli | last post by:
hello, i have the following problem: taking the pointer of a particular instantiation of template member function A::f. i have no idea of how achieve in the intent. :( any halp or hint would be very appreciated. cheers domenico
14
1610
by: Dennis | last post by:
Hi I have a little problem as stated above (haven't found any solution on the www). I have a list of objects (particles) where I have a member of a template vector (array1d from TNT). I initialise these members in the constructor, but when I write different vector values to different particles the values becomes the same. I have found out that each particles vector are pointing to the same address :o(
2
3448
by: Joshua Kolden | last post by:
STL allocators are templates so that when you write one you are obliged to make it work with any type. However, the Intel IPP library that we use has memory aligned allocators for each of 15 different types. For example an 8 bit unsigned array is allocated with ippsMalloc_8u(size). So I want to create memory aligned allocators for use with the STL (in particular the vector container) that is fast (due to alignment), and pointer...
3
7669
by: ecov | last post by:
Is there any easy way to read into a dataset a file that was created from a BCP command. The file is in a fixed length format. I would also like to be able to write out a dataset to the same type of file structure. The obvious solution would be to use XML file processing however that is not an option as I have a third party vendor that is not capable of processing XML files.
6
1927
by: rep_movsd | last post by:
Hi folks I was on topcoder and came across an interesting problem... It involved dynamic programming ( storing function results in a map to avoid repeated computation ) and I ended up having to write 3 functions that looked pretty much the same, so I thought- "Why not template - ize the whole thing" and ended up with a generic Memoizer template, which can be used to memoize any recursive function whose result depends on multiple...
6
2326
by: Angel Tsankov | last post by:
How can an overloaded operator& take the address of its argument: template<typename T> Smth operator &(T& SomeObject) { // The address of SomeObject is needed here }
1
2563
by: Beorne | last post by:
I have a cpp application with this structure: //////////////C++/////////////// typedef struct StatusStructure { char FixedLenString; long LongVariable; double DoubleVariable; BOOL BoolVariable; } StatusStructure;
1
2765
by: shofu_au | last post by:
Hi Group, I am trying to define a class that has a fixed size array of a structure containing a fixed size array of a structure. I am using System.Runtime.InteropServices and trying to define the fixed size using In the attached console application example when I try to address the fields in the class I get an execption.
0
9690
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
9551
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
10275
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10253
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10033
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
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
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
3
2945
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.