Re: Technical two dimensional array question




"Jesika" wrote...

> Given the following declaration:
>
> string [,] varray = new string[3,5]; (15 blocks of memory)
>
> Does it allocate a contiguous blocks of memory or not?

It does not.

At least not in the way I think you mean.

What it allocates is memory space for *references* to string objects, not
space for the objects themselves.

> What If I tried to go out of range but in a knowingly
> safe manner like the following in order to assign to
> the next array out of the 3 arrays:
>
> varray[0,5] = "string object"; // out of range overflow
> console.writeline(varray[0,1]);
>
> I tried it and I get an exception error, as I should, but,
> I also tried catching the exception to allow it to work
> but the problem is that the exception blocked my program
> before the assignment could occur; proving why I
> said it did not work. Am I wrong on this last assumption?

I don't even understand what you mean when you say that you "catch the
exception to allow it to work"?

If an exception is thrown because it isn't allowed, it won't be allowed
ever...

> In C, something like this particular program would work
> becuase C is not very strict when it comes to safety conforms.

Which is one of the problems of C.

In a C implementation that memory space could very well be occupied by
something else, which you'll destroy by exceeding the boundaries of the
allocated array.

// Bjorn A


.



Relevant Pages

  • Re: Another C# marshaling question
    ... // Get the pointer of the location in memory. ... > public static extern int FF_Function( ... > // Allocate the array. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: INTENT(WORKSPACE) as a new Fortran feature?
    ... >> the array once in the caller than each time within the subroutine. ... > the stack pointer is being changed to allocate local variables in any ... "actual" memory would never be touched at all. ... If, on a particular machine, the compiler knows that it would be ...
    (comp.lang.fortran)
  • Re: Storing the size of an array in the structure itself
    ... >> I think every C programmer can relate to the frustrations that malloc ... >> the size of an array must be stored separately to be a nightmare. ... is anything more than just that - a chunk of memory. ... > Otherwise you couldn't tell it how much to allocate. ...
    (comp.lang.c)
  • Re: Creating a logical matrix in a mex-file
    ... Then use mxMalloc to allocate the memory ... Use mxSetData to set the data of the array to the ... This would avoid the initialization of the memory. ...
    (comp.soft-sys.matlab)
  • Re: The problems arrayed before me...
    ... > When an array is grown, how does Delphi manage this cleanly? ... default memory manager, the first thing it tries to do, when it receives ... When you ask for a certain amount of memory, the memory manager is free ... to allocate more than you ask for, and it keeps track of that. ...
    (alt.comp.lang.borland-delphi)