Struct with fixed-length array member - is it possible?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hello,


Can you provide some hints on how would you solve a problem like this? I'm
out of ideas...
Here's the problem: Let's imagine a C structure containing a fixed-size
array

struct XYZ
{
int V1;
int V2;
double V3[50];
};

This structure, when allocated, occupies a contiguous block of memory (408
bytes in my compiler).
Now I would like to have the same structure in C#, such that it would have
THE SAME MEMORY LAYOUT as the C structure. The memory size does not need to
be identical as in C, but the structure should occupy a single memory block
and all data, including the array, should be placed in this block.

There is no possibility in C# to declare a fixed-size array and to 'embed'
it completely in a struct. When I make a declaration like this:

public struct XYZ
{
int V1;
int V2;
double[] V3;
}

the V3 member is a reference to array object, not the array itself.
Can you think of any way to get the C/C++ layout?

Best Regards,
Rafal Gwizdala


.



Relevant Pages

  • Re: Prime Numbers
    ... /*This code finally compiles as a 'c' code ... One more question....if i don't free up the memory allocated at the end ... it would appear that we are best served by an array ... prime numbers can be represented by an unsigned long int. ...
    (comp.lang.c)
  • Re: Java Indexing- Historical question
    ... And when the array is of primitives there should be a dramatic benefit in memory usage as well. ... RestrictedRangeIntegerKeyedMapif you prefer) implements Mapthat only accepted keys in a given range, and stored its elements in an array. ... public ArrayMap(int base, int size) { ...
    (comp.lang.java.programmer)
  • Re: NotSupportedException TomTomSDK
    ... The easiest way to marshal this data is as a byte array. ... use the System.Text.Encoding.Unicode.GetString to extract the inline string. ... BitConverter will allow you to get the int members out of the byte ... > Any ideas how to declare the TCHAR? ...
    (microsoft.public.pocketpc.developer)
  • Re: Exporting variables in and out subroutines (F77)
    ... F77 doesn't have the kind of dynamic ... >>memory capabilities you seem to be looking for in your ... >>n as a parameter in program helpme and declare A to have ... a big array in the main program and only use part of it. ...
    (comp.lang.fortran)
  • Re: contiguity of arrays
    ... Dan.Pop@cern.ch (Dan Pop) writes: ... There is nothing magic about dynamically allocated memory. ... object and then used to access such an object or an array of such ... could disallow ptrbecause the relevant array of int is only 2 ...
    (comp.lang.c)