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

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




"Rafal Gwizdala" <gwrafal@xxxxxxxxxxxxxx> wrote in message
news:uD0e2CGRFHA.1172@xxxxxxxxxxxxxxxxxxxxxxx
> 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;
> }
>

2.0 offers this, finally, using the fixed keyword


public stuct XYZ
{
fixed double V3[50];
}

This requires unsafe code, however.


.



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: 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)
  • Re: memory and speed
    ... but only handles int to save resource/memory ... The size of the IntVector could grow very big, such as 50000, ... Please comment my code regarding the speed and memory usage, ... Instead of keeping all the values in one array whose ...
    (comp.lang.java.programmer)
  • Re: Standard integer types vs types
    ... Not all integers count things in memory. ... I could simply replace that array with a switch statement with no ... an int to temporarily hold the value of errno when I must preserve it ...
    (comp.lang.c)