Click here to Skip to main content
16,007,885 members
Home / Discussions / C#
   

C#

 
AnswerRe: Unsafe code Pin
Christian Graus28-Apr-07 16:50
protectorChristian Graus28-Apr-07 16:50 
GeneralRe: Unsafe code Pin
xibeifeijian28-Apr-07 17:12
xibeifeijian28-Apr-07 17:12 
GeneralRe: Unsafe code Pin
Arun.Immanuel28-Apr-07 17:14
Arun.Immanuel28-Apr-07 17:14 
GeneralRe: Unsafe code Pin
Christian Graus28-Apr-07 17:44
protectorChristian Graus28-Apr-07 17:44 
GeneralRe: Unsafe code Pin
Arun.Immanuel28-Apr-07 17:48
Arun.Immanuel28-Apr-07 17:48 
AnswerRe: Unsafe code Pin
Luc Pattyn28-Apr-07 22:38
sitebuilderLuc Pattyn28-Apr-07 22:38 
GeneralRe: Unsafe code Pin
Christian Graus29-Apr-07 0:39
protectorChristian Graus29-Apr-07 0:39 
AnswerRe: Unsafe code Pin
Guffa29-Apr-07 1:10
Guffa29-Apr-07 1:10 
It should also be mentioned that the code isn't guaranteed to work if the variables hadn't been allocated on the stack.

If it uses a real object that is allocated on the heap:

public unsafe void Test() {
   string x = 42.ToString();
   string* px = &x; // Dangerous!
   *px += 1;
   Console.Write(*px);
}

The variable x is still allocated on the stack, but it is a reference to a string object that is allocated on the heap. If you copy the reference to a pointer, you will get the current location of the string in memory, but as the garbage collector can move objects in the heap, there is no guarantee that the string will stay in that location. It can be moved to another location at any moment, and the garbage collector will update the reference x to point to the new location, but it will not update the pointer px.


---
single minded; short sighted; long gone;

QuestionSyntax highlighting textbox Pin
Adobe200728-Apr-07 15:33
Adobe200728-Apr-07 15:33 
AnswerRe: Syntax highlighting textbox Pin
Dave Kreskowiak28-Apr-07 15:41
mveDave Kreskowiak28-Apr-07 15:41 
GeneralRe: Syntax highlighting textbox Pin
Adobe200728-Apr-07 16:16
Adobe200728-Apr-07 16:16 
GeneralRe: Syntax highlighting textbox Pin
Dave Kreskowiak28-Apr-07 17:07
mveDave Kreskowiak28-Apr-07 17:07 
AnswerRe: Syntax highlighting textbox Pin
Patrick Etc.28-Apr-07 17:40
Patrick Etc.28-Apr-07 17:40 
QuestionHow do I open a file? Pin
c.bartsch28-Apr-07 11:34
c.bartsch28-Apr-07 11:34 
AnswerRe: How do I open a file? Pin
MoustafaS28-Apr-07 12:15
MoustafaS28-Apr-07 12:15 
AnswerRe: How do I open a file? Pin
Dave Kreskowiak28-Apr-07 12:55
mveDave Kreskowiak28-Apr-07 12:55 
GeneralRe: How do I open a file? Pin
c.bartsch28-Apr-07 22:35
c.bartsch28-Apr-07 22:35 
GeneralRe: How do I open a file? Pin
lmoelleb28-Apr-07 22:59
lmoelleb28-Apr-07 22:59 
GeneralRe: How do I open a file? Pin
c.bartsch28-Apr-07 23:47
c.bartsch28-Apr-07 23:47 
GeneralRe: How do I open a file? Pin
Dave Kreskowiak29-Apr-07 2:19
mveDave Kreskowiak29-Apr-07 2:19 
GeneralRe: How do I open a file? Pin
c.bartsch29-Apr-07 8:41
c.bartsch29-Apr-07 8:41 
GeneralRe: How do I open a file? Pin
Dave Kreskowiak30-Apr-07 7:55
mveDave Kreskowiak30-Apr-07 7:55 
QuestionHow to improve Windows application performance? Pin
engsrini28-Apr-07 11:14
engsrini28-Apr-07 11:14 
AnswerRe: How to improve Windows application performance? Pin
kubben28-Apr-07 12:57
kubben28-Apr-07 12:57 
Questionnew Double Buffering Pin
HexaDeveloper28-Apr-07 10:58
HexaDeveloper28-Apr-07 10:58 

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.