471,330 Members | 1,437 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 software developers and data experts.

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 834

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Cgacc20 | last post: by
2 posts views Thread by Domenico Andreoli | last post: by
2 posts views Thread by Joshua Kolden | last post: by
3 posts views Thread by ecov | last post: by
6 posts views Thread by rep_movsd | last post: by

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.