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.writeli ne(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 1358
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.writeli ne(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.writeli ne(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****@discuss ions.microsoft. com> wrote in message
news:4D******** *************** ***********@mic rosoft.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.writeli ne(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 way to do this is a nested for-loop - but we all know
O(n^2) is bad. So I am looking for something like ArrayList.ToArray(),
or Matlabs A(:).
C#
|
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 dimensional arrays from
std::vectors ??? I want to use normal Array Syntax.
|
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 different models of cars that are produced by the car manufacturer.
Task 1
Step 1: Create a directory called Assignment02 and create the files of steps 2, 3 and 4 in this directory as well as your project file.
Step 2: Create a file called...
|
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 = { { 3.14 }, { 42.6 } };
f((double *)array, sizeof array / sizeof **array);
return 0;
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |