Click here to Skip to main content
15,889,216 members
Home / Discussions / C#
   

C#

 
AnswerRe: can you help me Pin
sweet_memory30-Jun-10 11:23
sweet_memory30-Jun-10 11:23 
GeneralRe: can you help me Pin
OriginalGriff1-Jul-10 0:53
mveOriginalGriff1-Jul-10 0:53 
AnswerRe: can you help me Pin
I Believe In GOD30-Jun-10 8:52
I Believe In GOD30-Jun-10 8:52 
AnswerRe: can you help me Pin
yu-jian30-Jun-10 18:23
yu-jian30-Jun-10 18:23 
QuestionHow to convert DataTable to MSDATASRC? Pin
vineesh v30-Jun-10 0:29
vineesh v30-Jun-10 0:29 
QuestionHow to invoke native MyFunction(MyStruct* myStructs, unsigned int nMyStructs) from C#? Pin
Chesnokov Yuriy29-Jun-10 22:39
professionalChesnokov Yuriy29-Jun-10 22:39 
AnswerRe: How to invoke native MyFunction(MyStruct* myStructs, unsigned int nMyStructs) from C#? Pin
freakyit1-Jul-10 4:50
freakyit1-Jul-10 4:50 
AnswerRe: How to invoke native MyFunction(MyStruct* myStructs, unsigned int nMyStructs) from C#? Pin
Daniel Grunwald2-Jul-10 0:24
Daniel Grunwald2-Jul-10 0:24 
You can allocate the memory whereever you want. A simple solution might be to allocate it in managed memory as .NET array:
MyStruct[] myStructs = new MyStruct[N];
fixed (MyStruct* pMyStructs = myStructs) {
   // fixed statement ensures the GC doesn't move the memory block while we access it using an unmanaged pointer
   MyFunction(pMyStructs, N);
}

In this case, the GC will take care of freeing the memory.

You can also allocate on the stack (if N is small, for large N you would risk a stack overflow):
MyStruct* pMyStructs = stackalloc MyStruct[N];
MyFunction(pMyStructs, N);

In this case, the memory is freed immediately when leaving the function that allocated it.

If you want to allocate in the unmanaged heap, then use one of the allocation functions in the Marshal class:
IntPtr memory = Marshal.AllocHGlobal(N * sizeof(MyStruct));
try {
	MyStruct* pMyStructs = (MyStruct*)memory.ToPointer();
	MyFunction(pMyStructs, N);
} finally {
	Marshal.FreeHGlobal(memory);
}


You could use Marshal.Copy to copy data from a managed array to an unmanaged pointer - but if you already have a managed array, you can simply use the first approach (fixed statement) to pass that without having to copy anything.
Questionbluetooth transfer issue Pin
Sajjad Izadi29-Jun-10 21:23
Sajjad Izadi29-Jun-10 21:23 
AnswerRe: bluetooth transfer issue Pin
Giorgi Dalakishvili30-Jun-10 2:57
mentorGiorgi Dalakishvili30-Jun-10 2:57 
Questionpicture box in win forms Pin
vamsi.ramesh00729-Jun-10 20:13
vamsi.ramesh00729-Jun-10 20:13 
AnswerRe: picture box in win forms Pin
Abhinav S29-Jun-10 20:56
Abhinav S29-Jun-10 20:56 
QuestionChanging control rectangle color? Pin
Megidolaon29-Jun-10 13:22
Megidolaon29-Jun-10 13:22 
AnswerRe: Changing control rectangle color? Pin
Adam R Harris29-Jun-10 13:48
Adam R Harris29-Jun-10 13:48 
AnswerRe: Changing control rectangle color? Pin
Ravi Bhavnani29-Jun-10 13:59
professionalRavi Bhavnani29-Jun-10 13:59 
AnswerRe: Changing control rectangle color? Pin
Dr.Walt Fair, PE29-Jun-10 14:07
professionalDr.Walt Fair, PE29-Jun-10 14:07 
AnswerRe: Changing control rectangle color? Pin
V.29-Jun-10 21:15
professionalV.29-Jun-10 21:15 
AnswerRe: Changing control rectangle color? Pin
Megidolaon30-Jun-10 12:21
Megidolaon30-Jun-10 12:21 
GeneralRe: Changing control rectangle color? Pin
Adam R Harris2-Jul-10 7:14
Adam R Harris2-Jul-10 7:14 
Questionc sharp learning Pin
netJP12L29-Jun-10 11:24
netJP12L29-Jun-10 11:24 
AnswerRe: c sharp learning Pin
Dave Kreskowiak30-Jun-10 1:38
mveDave Kreskowiak30-Jun-10 1:38 
Questioncan I make zooming in the form itself ? Pin
Honeyboy_2029-Jun-10 8:54
Honeyboy_2029-Jun-10 8:54 
AnswerRe: can I make zooming in the form itself ? Pin
Ennis Ray Lynch, Jr.29-Jun-10 9:20
Ennis Ray Lynch, Jr.29-Jun-10 9:20 
AnswerRe: can I make zooming in the form itself ? Pin
Gonzalo Cao30-Jun-10 1:53
Gonzalo Cao30-Jun-10 1:53 
QuestionC# ComboBox (DataBound) for display Pin
maxpfc29-Jun-10 6:50
maxpfc29-Jun-10 6:50 

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.