c# - Marshaling a struct that has a variable array with zero elements -


.net 4 64bit. have c# structure intend marshal c

[structlayout(layoutkind.sequential)] public struct parentstruct {     public float[] farray;     public int farraylength; } 

to

struct parentstruct {     float* farray;     int farraylength; }; 

the special circumstances here array need copy float[] farray pinned , has 0 elements , interested in copying pointer across native , not interested in actual elements has (which none!) nor in allocating memory on native side on free store (heap), pointing garbage location, fine.

the technical reason doing float[] farray pointing address on gpu memory , once marshaled gpu, pointing right data.

i want able marshal struct c, not sure proper marshal way

  • i tried marshaling in current structure, got object contains non-primitive or non-blittable data.
  • i tried adding [marshalas(unmanagedtype.lparray)] , getting type 'test.parentstruct' cannot marshaled unmanaged structure; no meaningful size or offset can computed.

by way, understand why getting these errors, want way marshal given array not variable array (but looks 1 interop libraries) , can think of struct fixed size.

n.b. have use float[] rather uint or because of intellisense , other constraints.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -