Click here to Skip to main content
16,005,281 members
Home / Discussions / C#
   

C#

 
AnswerRe: using ZedGraph + *.txt file Pin
OriginalGriff27-Dec-11 8:19
mveOriginalGriff27-Dec-11 8:19 
GeneralRe: using ZedGraph + *.txt file Pin
housepl27-Dec-11 8:28
housepl27-Dec-11 8:28 
GeneralRe: using ZedGraph + *.txt file Pin
OriginalGriff27-Dec-11 8:30
mveOriginalGriff27-Dec-11 8:30 
QuestionUnsafe code safety question Pin
Lutosław27-Dec-11 4:47
Lutosław27-Dec-11 4:47 
AnswerRe: Unsafe code safety question Pin
harold aptroot27-Dec-11 5:01
harold aptroot27-Dec-11 5:01 
GeneralRe: Unsafe code safety question Pin
Lutosław27-Dec-11 5:40
Lutosław27-Dec-11 5:40 
GeneralRe: Unsafe code safety question Pin
harold aptroot27-Dec-11 6:04
harold aptroot27-Dec-11 6:04 
GeneralRe: Unsafe code safety question Pin
Lutosław27-Dec-11 6:55
Lutosław27-Dec-11 6:55 
harold aptroot wrote:
Why is this? I've written plenty of loops spanned by a fixed.

If you have a single pointer then it is possible. But if you had an array of strings A, then you cannot pull the fixed statement outside the loop since you do not have an indexer:
while(...) // m times
for(int i = 0; i<len; i++)
{
   // cannot move outside of loop, neither this nor the outer one
   // so we end up with n*m fixed statements
   fixed(char* str = A[i])
}

Solution:
// pin the array's elements
GCHandle[] handles= new GCHandle[len];
for (int i = 0; i < len; i++)
{
    handles[i] = GCHandle.Alloc(A[i], GCHandleType.Pinned);
}
while(...) // m times
for(int i = 0; i<len; i++)
{
   // get pinned:
   char* str = (char*)handles[i].AddrOfPinnedObject()
}
//free handles
for (int i = 0; i < len; i++)
{
    handles[i].Free();
}

Note: I use memcpy and memcmp inside, so yes there is some P/Invoke shift involved.
Greetings - Jacek


modified 27-Dec-11 13:15pm.

GeneralRe: Unsafe code safety question Pin
harold aptroot27-Dec-11 7:08
harold aptroot27-Dec-11 7:08 
GeneralRe: Unsafe code safety question Pin
Lutosław27-Dec-11 7:16
Lutosław27-Dec-11 7:16 
GeneralRe: Unsafe code safety question Pin
Lutosław27-Dec-11 8:43
Lutosław27-Dec-11 8:43 
GeneralRe: Unsafe code safety question Pin
harold aptroot27-Dec-11 9:06
harold aptroot27-Dec-11 9:06 
GeneralRe: Unsafe code safety question Pin
PIEBALDconsult27-Dec-11 6:06
mvePIEBALDconsult27-Dec-11 6:06 
AnswerRe: Unsafe code safety question Pin
PIEBALDconsult27-Dec-11 5:01
mvePIEBALDconsult27-Dec-11 5:01 
GeneralRe: Unsafe code safety question Pin
Lutosław27-Dec-11 5:26
Lutosław27-Dec-11 5:26 
GeneralRe: Unsafe code safety question Pin
PIEBALDconsult27-Dec-11 5:28
mvePIEBALDconsult27-Dec-11 5:28 
AnswerRe: Unsafe code safety question Pin
jschell27-Dec-11 10:18
jschell27-Dec-11 10:18 
QuestionResizing Controls According to Forms' Size Pin
AmbiguousName27-Dec-11 2:15
AmbiguousName27-Dec-11 2:15 
AnswerRe: Resizing Controls According to Forms' Size Pin
PIEBALDconsult27-Dec-11 2:29
mvePIEBALDconsult27-Dec-11 2:29 
AnswerRe: Resizing Controls According to Forms' Size Pin
David C# Hobbyist.27-Dec-11 2:34
professionalDavid C# Hobbyist.27-Dec-11 2:34 
AnswerRe: Resizing Controls According to Forms' Size Pin
Shameel27-Dec-11 4:08
professionalShameel27-Dec-11 4:08 
AnswerRe: Resizing Controls According to Forms' Size Pin
BillWoodruff27-Dec-11 4:38
professionalBillWoodruff27-Dec-11 4:38 
GeneralRe: Resizing Controls According to Forms' Size Pin
Roger Wright27-Dec-11 20:58
professionalRoger Wright27-Dec-11 20:58 
GeneralRe: Resizing Controls According to Forms' Size Pin
BillWoodruff29-Dec-11 2:31
professionalBillWoodruff29-Dec-11 2:31 
GeneralRe: Resizing Controls According to Forms' Size Pin
BobJanova30-Dec-11 14:44
BobJanova30-Dec-11 14:44 

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.