Click here to Skip to main content
15,887,596 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to pin List to unmanaged byte** [modified] Pin
DaveyM6919-Jan-11 8:48
professionalDaveyM6919-Jan-11 8:48 
AnswerRe: How to pin List to unmanaged byte** Pin
DaveyM6919-Jan-11 9:23
professionalDaveyM6919-Jan-11 9:23 
AnswerRe: How to pin List to unmanaged byte** Pin
Chesnokov Yuriy19-Jan-11 9:35
professionalChesnokov Yuriy19-Jan-11 9:35 
GeneralRe: How to pin List to unmanaged byte** Pin
DaveyM6919-Jan-11 9:41
professionalDaveyM6919-Jan-11 9:41 
AnswerRe: How to pin List to unmanaged byte** Pin
Chesnokov Yuriy19-Jan-11 10:04
professionalChesnokov Yuriy19-Jan-11 10:04 
GeneralRe: How to pin List to unmanaged byte** Pin
DaveyM6919-Jan-11 10:14
professionalDaveyM6919-Jan-11 10:14 
AnswerRe: How to pin List to unmanaged byte** Pin
Chesnokov Yuriy19-Jan-11 19:02
professionalChesnokov Yuriy19-Jan-11 19:02 
GeneralRe: How to pin List to unmanaged byte** Pin
_Erik_19-Jan-11 3:06
_Erik_19-Jan-11 3:06 
The List<T> class has an inner private field (_items) which is an array of T. You might retrieve it using reflection, but there is a problem: you do not have control over the size of this array unless you specify its capacity. If you want to pass the arrays without making any copy of it, your best choice is to develop a new class for this, using a two dimensional array, I mean, a byte[,] instead of a byte[][], as a field to hold the data, and maybe wrap the P/Invoke call within this class. This way you can use the reference without making any copy and, also, you will be sure that everything in memory has the size it should. Something like:

C#
public class ByteMatrix
{
    byte[,] _matrix;
    int _n;
    int _m;

    public ByteMatrix(int n, int m)
    {
        _matrix = new byte[n, m];
        _n = n;
        _m = m;
    }

    // Methods, indexers and properties to add, remove, etc, as needed

    // Import the unmanaged function here, as private
    [DllImport ... whatever]
    private static extern int unmanagedFunction(byte[,] array, int n, int m);

    // Wrap the unmanaged function whithin this class
    public int CallUnmanaged() // Here a good name, of course
    {
        return unmanagedFunction(_matrix, _n, _m);
    }
}

GeneralRe: How to pin List to unmanaged byte** Pin
Chesnokov Yuriy19-Jan-11 4:18
professionalChesnokov Yuriy19-Jan-11 4:18 
GeneralRe: How to pin List to unmanaged byte** Pin
_Erik_19-Jan-11 5:10
_Erik_19-Jan-11 5:10 
AnswerRe: How to pin List to unmanaged byte** Pin
Chesnokov Yuriy19-Jan-11 9:45
professionalChesnokov Yuriy19-Jan-11 9:45 
GeneralRe: How to pin List to unmanaged byte** [modified] Pin
_Erik_19-Jan-11 10:55
_Erik_19-Jan-11 10:55 
AnswerRe: How to pin List to unmanaged byte** Pin
Chesnokov Yuriy19-Jan-11 19:12
professionalChesnokov Yuriy19-Jan-11 19:12 
GeneralRe: How to pin List to unmanaged byte** Pin
_Erik_20-Jan-11 2:37
_Erik_20-Jan-11 2:37 
AnswerRe: How to pin List to unmanaged byte** Pin
Chesnokov Yuriy19-Jan-11 4:27
professionalChesnokov Yuriy19-Jan-11 4:27 
AnswerRe: How to pin List<byte[]> to unmanaged byte** Pin
SledgeHammer0118-Jan-11 9:33
SledgeHammer0118-Jan-11 9:33 
AnswerRe: How to pin List to unmanaged byte** Pin
Chesnokov Yuriy18-Jan-11 19:08
professionalChesnokov Yuriy18-Jan-11 19:08 
GeneralRe: How to pin List to unmanaged byte** Pin
SledgeHammer0119-Jan-11 10:25
SledgeHammer0119-Jan-11 10:25 
AnswerRe: How to pin List to unmanaged byte** Pin
Chesnokov Yuriy19-Jan-11 19:03
professionalChesnokov Yuriy19-Jan-11 19:03 
GeneralRe: How to pin List to unmanaged byte** [modified] Pin
SledgeHammer0120-Jan-11 8:41
SledgeHammer0120-Jan-11 8:41 
QuestionOn Error Resume Next Pin
Anubhava Dimri17-Jan-11 18:24
Anubhava Dimri17-Jan-11 18:24 
AnswerRe: On Error Resume Next PinPopular
JF201517-Jan-11 18:31
JF201517-Jan-11 18:31 
GeneralRe: On Error Resume Next Pin
Anubhava Dimri17-Jan-11 19:09
Anubhava Dimri17-Jan-11 19:09 
GeneralRe: On Error Resume Next Pin
fjdiewornncalwe18-Jan-11 8:56
professionalfjdiewornncalwe18-Jan-11 8:56 
AnswerRe: On Error Resume Next Pin
Dave Kreskowiak17-Jan-11 18:59
mveDave Kreskowiak17-Jan-11 18:59 

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.