473,382 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

is this correct?

Tell me if this is the correct reasoning for this situation.

I have two objects, both are structures and have identical data in the
structure. I place one into a queue object, now if i do a contains on the
queue of the second object it wont contain the first object because they are
independent memory locations (seperate objects) even though they are
identical and not pointers to each other. What I have is a queue of file
names that I need to process. Each file name has a structure that has a path
and its full file name. Now when They get placed into a queue i need to make
sure they file does not already exist in queue, but since they are
structures, each entry is an independent object, so if i have a file in
queue and then the same file name comes up later its a newly created object.
Even though they are the same file in reality, now they have two objects
representing themselves.
Nov 21 '05 #1
2 969

"Brian Henry" <no****@nospam.newsgroups> wrote
Tell me if this is the correct reasoning for this situation.


Rather than what appears to be speculation, why not look in
the Help file and learn what the framework does when comparing
structures?

First, you find from a Queue's Contains method that it expects an
Object as a parameter. This should tell you right away that there
will be added overhead in boxing the structure to make it an Object.

Next you find that Contains uses the .Equals method to determine
if there is a match. And, knowing that structures are Value types,
you can look up the ValueType.Equals method in Help to see
what it does:

--------------- (From its Remarks section)
Remarks
The default implementation of the Equals method uses reflection to compare the
corresponding fields of obj and this instance. Override the Equals method for
a particular type to improve the performance of the method and more closely
represent the concept of equality for the type.
----------------

Also look there for their example of overriding the Equals method (as mentioned
above).

But I have to ask, why not just test it with some code? Then if it doesn't
act as you suspect, find out why, or post a question on that. You stand a
better chance at understanding, and retaining the knowlege gained if you
do the needed research yourself, before asking others to do the research for you....

Finally, (in case you missed it), due to your need for using a structure like an
object, you would be better off to just use a class that has the properties you
need.

HTH
LFS

Nov 21 '05 #2
I did test it first, that was why I was asking if I was correct because the
test failed.. two structures trying to match with contains did not return a
match, which was what I expected because they are two independent objects

"Larry Serflaten" <se*******@usinternet.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...

"Brian Henry" <no****@nospam.newsgroups> wrote
Tell me if this is the correct reasoning for this situation.


Rather than what appears to be speculation, why not look in
the Help file and learn what the framework does when comparing
structures?

First, you find from a Queue's Contains method that it expects an
Object as a parameter. This should tell you right away that there
will be added overhead in boxing the structure to make it an Object.

Next you find that Contains uses the .Equals method to determine
if there is a match. And, knowing that structures are Value types,
you can look up the ValueType.Equals method in Help to see
what it does:

--------------- (From its Remarks section)
Remarks
The default implementation of the Equals method uses reflection to compare
the
corresponding fields of obj and this instance. Override the Equals method
for
a particular type to improve the performance of the method and more
closely
represent the concept of equality for the type.
----------------

Also look there for their example of overriding the Equals method (as
mentioned
above).

But I have to ask, why not just test it with some code? Then if it
doesn't
act as you suspect, find out why, or post a question on that. You stand a
better chance at understanding, and retaining the knowlege gained if you
do the needed research yourself, before asking others to do the research
for you....

Finally, (in case you missed it), due to your need for using a structure
like an
object, you would be better off to just use a class that has the
properties you
need.

HTH
LFS

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: David Opstad | last post by:
I have a question about text rendering I'm hoping someone here can answer. Is there a way of doing linguistically correct rendering of Unicode strings in Python? In simple cases like Latin or...
0
by: Sarah Tegtmeier | last post by:
Hi I have a question about the correct use of the attribute xsi:schemaLocation. My programm has to process XML files where the value of this attribute causes some problems. The programm is...
1
by: Richard Golebiowski | last post by:
I have been trying to figure this out for quite some time and cannot find any examples in VB.Net or in VB that work correctly. I am working on an application where I want the user to be able to...
14
by: john.burton.email | last post by:
I've done some extensive searching and can't seem to find an answer to this - Is it correct to using "using" with templates, for example: using std::vector; Or do I need to specify the type...
6
by: Rob Thorpe | last post by:
Given the code:- r = sscanf (s, "%lf", x); What is the correct output if the string s is simply "-" ? If "-" is considered the beginning of a number, that has been cut-short then the...
5
by: blackg | last post by:
Input string not in correct format -------------------------------------------------------------------------------- I am trying to view a picture from a table. I am getting this error Input string...
2
by: thisis | last post by:
Hi All, I need the PUBS.mdb for pulling images: PUBS.mdb must have the table: pub_info tbl_pub_info : has 3 fields Data_Type : ok Data_Type : ok
0
by: sehguh | last post by:
Hiya Folks, I am Currently using windows xp. Also using Visual Web Developer 2005 and Microsoft Sql server 2005. The main page consists of an aspx page and a master page. The page also...
3
lee123
by: lee123 | last post by:
I have a problem getting the correct to count +1 every time I get an answer right and the incorrect is the same. I have two lbl's named number1 and number2 which produces a Rnd# in each lbl. ...
10
by: onetruelove | last post by:
I want to creat a post like this blog: http://onlinetoefltest.blogspot.com/2007/08/level-c-lesson-1.html When you chose all the answers and click show answer a msg box will appear and tells how...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.