Hi, I have a cumbersome question:
Given the following declaration:
string [,] varray = new string[3,5]; (15 blocks of memory)
Does it allocate a contiguous blocks of memory or not? If it does,
is it guaranteed to be contiguous everytime?
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?
In C, something like this particular program would work becuase C is not
very strict when it comes to safety conforms.
I would appreciate if someone could answer these two questions for me, and
also, if I could be refered to a book that gets into the nity-gritty
technicalities of C# semantics. Especially concerning with the subject of
this thread.
Thanks in advance,
Jesika. 3 1347
Jesika,
I think the issue here is not that you need to worry about memory usage,
since by definition managed code has full "memory management".
The issue is, when you have declared an array you cannot change it. A
string[3,5] array can only be changed by creating a new array and copying its
contents.
Trying to "work around" the runtime by catching an exception and then
merrily sailing on with something new like this isn't going to work.
Hope that helps.
Peter
--
Co-founder, Eggheadcafe.com developer portal: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
"Jesika" wrote: Hi, I have a cumbersome question:
Given the following declaration:
string [,] varray = new string[3,5]; (15 blocks of memory)
Does it allocate a contiguous blocks of memory or not? If it does, is it guaranteed to be contiguous everytime?
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?
In C, something like this particular program would work becuase C is not very strict when it comes to safety conforms.
I would appreciate if someone could answer these two questions for me, and also, if I could be refered to a book that gets into the nity-gritty technicalities of C# semantics. Especially concerning with the subject of this thread.
Thanks in advance, Jesika.
"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
inline
Willy.
"Jesika" <Je****@discussions.microsoft.com> wrote in message
news:4D**********************************@microsof t.com... Hi, I have a cumbersome question:
Given the following declaration:
string [,] varray = new string[3,5]; (15 blocks of memory)
Does it allocate a contiguous blocks of memory or not? If it does, is it guaranteed to be contiguous everytime?
Yes, the array of "string references" is guaranteed to be contigious.
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?
You can catch (and swallow) the exception, but you can never assign a
reference to a location that is outside of the array bounds. Why would you
ever wanna do this?
In C, something like this particular program would work becuase C is not very strict when it comes to safety conforms.
No, such program contains a bug, it can seeingly work, but sooner or later
it will fail as you are overwriting whatever is located after the last array
element.
I would appreciate if someone could answer these two questions for me, and also, if I could be refered to a book that gets into the nity-gritty technicalities of C# semantics. Especially concerning with the subject of this thread.
Thanks in advance, Jesika. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: per9000 |
last post by:
Hi all,
I have a two-dimensional array of data, f.x int's. We can imagine that
the array is "really large". Now I want the data in it and store this
in a one-dimensional array.
The obvious...
|
by: Peter Olcott |
last post by:
http://groups.google.com/group/comp.lang.c++/msg/a9092f0f6c9bf13a
I think that the operator() member function does not work correctly, does
anyone else know how to make a template for making two...
|
by: nelly0 |
last post by:
developing a program that will manipulate noise levels (measured in decibels) that is collected by car manufacturers. These noise levels are produced at seven different speeds by a maximum of six...
|
by: vippstar |
last post by:
The subject might be misleading.
Regardless, is this code valid:
#include <stdio.h>
void f(double *p, size_t size) { while(size--) printf("%f\n", *p++); }
int main(void) {
double array = { {...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |