Click here to Skip to main content
15,843,322 members
Home / Discussions / C#
   

C#

 
GeneralRe: Treeview in a thread Pin
Nicholas Butler25-Oct-09 0:32
sitebuilderNicholas Butler25-Oct-09 0:32 
GeneralRe: Treeview in a thread Pin
Ronni Marker26-Oct-09 18:59
Ronni Marker26-Oct-09 18:59 
AnswerRe: Treeview in a thread Pin
Luc Pattyn25-Oct-09 13:35
sitebuilderLuc Pattyn25-Oct-09 13:35 
GeneralRe: Treeview in a thread Pin
Ronni Marker26-Oct-09 19:03
Ronni Marker26-Oct-09 19:03 
QuestionHow can i run the open and save file codes in C# ??? [modified] Pin
ghe143lhei24-Oct-09 20:59
ghe143lhei24-Oct-09 20:59 
AnswerRe: How can i run the open and save file codes in C# ??? Pin
OriginalGriff24-Oct-09 23:43
mveOriginalGriff24-Oct-09 23:43 
Questionhow to bind TreeView to hierarchical data (Recursive Queries) ? Pin
hdv21224-Oct-09 19:25
hdv21224-Oct-09 19:25 
QuestionAn array of valuetypes that contain ponters to other valuetypes in an array. [modified] Pin
CaptainSeeSharp24-Oct-09 14:13
CaptainSeeSharp24-Oct-09 14:13 
Consider the following...

struct Node
{
  unsafe { public Node* parentNode; }
  public int someData;
}


class SomeClass
{
  Node[] nodeArray = new Node[2];
  Node[] otherNodeArray = new Node[1];
  
  void LinkEmUp()
  {
    unsafe
    {  
      nodeArray[0].parentNode = &nodeArray[1];
      otherNodeArray[0].parentNode = &nodeArray[0];
    }
  }
}


And to add, lets say that an instance of SomeClass has a Node array where an element's parentNode points to a Node in another SomeClass instance's array.

Would the pointer chain will be intact after a garbage collection or after the CLR does something to change the reference types memory locations? Is it even possible to make linked lists and reference/pointer chains with .NET value types?

EDIT:

I figured it out. In the example above, the consumer of SomeClass would have to use the fixed statement to fix SomeClass and the two Node arrays. The Node arrays would also have to be made public so that the consumer can directly access them.

class SomeClass
{
  public Node[] nodeArray = new Node[2];
  public Node[] otherNodeArray = new Node[1];
  
  public void LinkEmUp()
  {
    unsafe
    {  
      nodeArray[0].parentNode = &nodeArray[1];
      otherNodeArray[0].parentNode = &nodeArray[0];
    }
  }
}


Consumer

unsafe static void Main()
{
  SomeClass c = new SomeClass();
  
  //pin SomeClass c and its member arrays, after leaving the scope of the fixed statement
  //the entire thing falls apart, the pointers the arrays are not used, there only to satisfy the requirements of C#
  fixed(Node* _temp = &c.nodeArray[0], __temp = &c.otherNodeAray[0])
  {
    c.LinkEmUp();
    //work with object, after leaving object is useless
    ...
  }
}


As far as my question about linked lists with C style structs, its possible if I use native API or Marshaling to allocate memory.

Another way is stack based linked lists built through recursion which I don't understand how it could be of any use that way.


modified on Saturday, October 24, 2009 11:28 PM

AnswerRe: An array of valuetypes that contain ponters to other valuetypes in an array. Pin
Christian Graus24-Oct-09 14:16
protectorChristian Graus24-Oct-09 14:16 
GeneralRe: An array of valuetypes that contain ponters to other valuetypes in an array. Pin
CaptainSeeSharp24-Oct-09 14:30
CaptainSeeSharp24-Oct-09 14:30 
GeneralRe: An array of valuetypes that contain ponters to other valuetypes in an array. PinPopular
Christian Graus24-Oct-09 15:12
protectorChristian Graus24-Oct-09 15:12 
GeneralRe: An array of valuetypes that contain ponters to other valuetypes in an array. Pin
Not Active24-Oct-09 16:47
mentorNot Active24-Oct-09 16:47 
GeneralRe: An array of valuetypes that contain ponters to other valuetypes in an array. Pin
Christian Graus25-Oct-09 0:24
protectorChristian Graus25-Oct-09 0:24 
GeneralRe: An array of valuetypes that contain ponters to other valuetypes in an array. Pin
Christian Graus24-Oct-09 15:42
protectorChristian Graus24-Oct-09 15:42 
GeneralRe: An array of valuetypes that contain ponters to other valuetypes in an array. [modified] Pin
CaptainSeeSharp24-Oct-09 17:01
CaptainSeeSharp24-Oct-09 17:01 
GeneralRe: An array of valuetypes that contain ponters to other valuetypes in an array. Pin
Christian Graus25-Oct-09 0:23
protectorChristian Graus25-Oct-09 0:23 
GeneralRe: An array of valuetypes that contain ponters to other valuetypes in an array. Pin
miss YY26-Oct-09 0:33
miss YY26-Oct-09 0:33 
Questioncaptcha image from WebBrowser into a picturebox Pin
yogesh_softworld12324-Oct-09 6:17
yogesh_softworld12324-Oct-09 6:17 
AnswerRe: captcha image from WebBrowser into a picturebox Pin
Abhishek Sur24-Oct-09 8:24
professionalAbhishek Sur24-Oct-09 8:24 
GeneralRe: captcha image from WebBrowser into a picturebox [modified] Pin
yogesh_softworld12324-Oct-09 8:33
yogesh_softworld12324-Oct-09 8:33 
GeneralRe: captcha image from WebBrowser into a picturebox Pin
Abhishek Sur24-Oct-09 8:38
professionalAbhishek Sur24-Oct-09 8:38 
GeneralRe: captcha image from WebBrowser into a picturebox Pin
yogesh_softworld12324-Oct-09 9:15
yogesh_softworld12324-Oct-09 9:15 
GeneralRe: captcha image from WebBrowser into a picturebox Pin
Abhishek Sur24-Oct-09 10:10
professionalAbhishek Sur24-Oct-09 10:10 
GeneralRe: captcha image from WebBrowser into a picturebox Pin
yogesh_softworld12324-Oct-09 10:39
yogesh_softworld12324-Oct-09 10:39 
GeneralRe: captcha image from WebBrowser into a picturebox Pin
Christian Graus24-Oct-09 11:18
protectorChristian Graus24-Oct-09 11:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.