473,387 Members | 1,561 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,387 software developers and data experts.

Accessing vector content even though size = 0

Hi group,

I'm writting a test at the moment where I want to inspect the content of a
vector that I uses as a buffer. The problem is that the function which
populates the vector also sends the vector and the send method performs a
resize(0). So when I try to inspect the vector afterwards, it appears empty.

I there a way to get a pointer to the beginning of the vector, since the
data is still there. Or is it possible to perform a resize(n) that doens't
zero out the content?

I now that the _Myfirst member of vector points to the beginning of the
vector, but thats a protected member and hence inaccessible.

Any ideas?

(I've tried using the #define protected public hack, but since the code
being tested is located in another compilation unit, I get a dllimport
error, since some of the methods being used are defined as protected)
Feb 19 '08 #1
7 1527
On 19 Feb, 10:08, "Hansen" <bluesb...@remove.the.spam.hotmail.com>
wrote:
Hi group,

I'm writting a test at the moment where I want to inspect the content of a
vector that I uses as a buffer. The problem is that the function which
populates the vector also sends the vector and the send method performs a
resize(0). So when I try to inspect the vector afterwards, it appears empty.

I there a way to get a pointer to the beginning of the vector, since the
data is still there. Or is it possible to perform a resize(n) that doens't
zero out the content?

I now that the _Myfirst member of vector points to the beginning of the
vector, but thats a protected member and hence inaccessible.

Any ideas?

(I've tried using the #define protected public hack, but since the code
being tested is located in another compilation unit, I get a dllimport
error, since some of the methods being used are defined as protected)
For a vector v, &*v.begin() and &v[0] yields a pointer to the first
element.
Feb 19 '08 #2
>I'm writting a test at the moment where I want to inspect the content of
>a
vector that I uses as a buffer. The problem is that the function which
populates the vector also sends the vector and the send method performs a
resize(0). So when I try to inspect the vector afterwards, it appears
empty.

I there a way to get a pointer to the beginning of the vector, since the
data is still there. Or is it possible to perform a resize(n) that
doens't
zero out the content?

I now that the _Myfirst member of vector points to the beginning of the
vector, but thats a protected member and hence inaccessible.

Any ideas?

(I've tried using the #define protected public hack, but since the code
being tested is located in another compilation unit, I get a dllimport
error, since some of the methods being used are defined as protected)

For a vector v, &*v.begin() and &v[0] yields a pointer to the first
element.
But when size=0 (due to the "hidden" resize(0) call) this causes a runtime
error. My problem is get the address of the vector even though size = 0.
Feb 19 '08 #3
On 19 Feb, 10:20, "Hansen" <bluesb...@remove.the.spam.hotmail.com>
wrote:
I'm writting a test at the moment where I want to inspect the content of
a
vector that I uses as a buffer. The problem is that the function which
populates the vector also sends the vector and the send method performs a
resize(0). So when I try to inspect the vector afterwards, it appears
empty.
I there a way to get a pointer to the beginning of the vector, since the
data is still there. Or is it possible to perform a resize(n) that
doens't
zero out the content?
I now that the _Myfirst member of vector points to the beginning of the
vector, but thats a protected member and hence inaccessible.
Any ideas?
(I've tried using the #define protected public hack, but since the code
being tested is located in another compilation unit, I get a dllimport
error, since some of the methods being used are defined as protected)
For a vector v, &*v.begin() and &v[0] yields a pointer to the first
element.

But when size=0 (due to the "hidden" resize(0) call) this causes a runtime
error. My problem is get the address of the vector even though size = 0.
If you are using VC++,
#define _SECURE_SCL 0
#define _HAS_ITERATOR_DEBUGGING 0

should disable those "nasty" runtime checks =)
Feb 19 '08 #4
[snip]
For a vector v, &*v.begin() and &v[0] yields a pointer to the first
element.

But when size=0 (due to the "hidden" resize(0) call) this causes a
runtime
error. My problem is get the address of the vector even though size = 0.

If you are using VC++,
#define _SECURE_SCL 0
#define _HAS_ITERATOR_DEBUGGING 0

should disable those "nasty" runtime checks =)
Problem is that I'm building for both win32 using VC++ and for StrongArm
using a Diab compiler.
But I'll note that little define trick into the "book of trick" :o)
Feb 19 '08 #5
On 2ÔÂ19ÈÕ, ÏÂÎç5ʱ08·Ö, "Hansen" <bluesb...@remove.the.spam.hotmail.com>
wrote:
Hi group,

I'm writting a test at the moment where I want to inspect the content of a
vector that I uses as a buffer. The problem is that the function which
populates the vector also sends the vector and the send method performs a
resize(0). So when I try to inspect the vector afterwards, it appears empty.

I there a way to get a pointer to the beginning of the vector, since the
data is still there. Or is it possible to perform a resize(n) that doens't
zero out the content?

I now that the _Myfirst member of vector points to the beginning of the
vector, but thats a protected member and hence inaccessible.

Any ideas?

(I've tried using the #define protected public hack, but since the code
being tested is located in another compilation unit, I get a dllimport
error, since some of the methods being used are defined as protected)
The easiest way for this problem is create a copy of the vector and
use the copy instead of the original vector as the parameter, like
this:

FuncProcessAndEmpty( vector<typeA>(vecA) );

instead of :

FuncProcessAndEmpty( vecA );

do not rely on resize() or something else - it dangerous!
Feb 19 '08 #6
In message <fp**********@news.net.uni-c.dk>, Hansen
<bl*******@remove.the.spam.hotmail.comwrites
>Hi group,

I'm writting a test at the moment where I want to inspect the content of a
vector that I uses as a buffer. The problem is that the function which
populates the vector also sends the vector and the send method performs a
resize(0).
Start with the real problem. *Why* does a function called "send"
actually perform "clear"?
>So when I try to inspect the vector afterwards, it appears empty.
It _is_ empty, by any standard-conforming interpretation.
>
I there a way to get a pointer to the beginning of the vector, since the
data is still there.
For some definition of "still there" involving the words "undefined
behaviour", maybe.
>Or is it possible to perform a resize(n) that doens't
zero out the content?
No.
>
I now that the _Myfirst member of vector points to the beginning of the
vector, but thats a protected member and hence inaccessible.
Because it's an implementation detail.
>
Any ideas?
Solve the real problem, which is in the algorithm, not the low-level
details.
>
(I've tried using the #define protected public hack,
UB.
>but since the code
being tested is located in another compilation unit, I get a dllimport
error, since some of the methods being used are defined as protected)

--
Richard Herring
Feb 19 '08 #7
"Hansen" <bl*******@remove.the.spam.hotmail.comwrote in message
news:fp**********@news.net.uni-c.dk...
I'm writting a test at the moment where I want to inspect the content of a
vector that I uses as a buffer. The problem is that the function which
populates the vector also sends the vector and the send method performs a
resize(0). So when I try to inspect the vector afterwards, it appears
empty.
Right. That's because it is empty.
I there a way to get a pointer to the beginning of the vector, since the
data is still there. Or is it possible to perform a resize(n) that doens't
zero out the content?
Calling resize(0) sets the size to zero. After that, the vector has no
content.
I now that the _Myfirst member of vector points to the beginning of the
vector, but thats a protected member and hence inaccessible.
If the size is zero, the vector has no beginning.
Any ideas?
If you are trying to inspect the content of vector, don't throw the content
away until after you've inspected it.
Feb 19 '08 #8

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

Similar topics

1
by: Abby Lee | last post by:
My page runs fine...I just get the yeld sign with a "!" in it. Ok, I asked this question in the VBscript group and they tell me it's a JavaScript issue even though I don't get the error until I...
2
by: Satish Gupta | last post by:
I am using DB2 7.2 on windows 2000. For some reason, DB2 now asks me for username/password when I try to open an instance tree in Control-Center even though I am logged in, although not as an...
1
by: Craig | last post by:
Hi, I'd just like to know why, when a System.Threading.Timer timer is fired, and I set a class variable to CurrentThread within the Timer method, that when calling Join on that thread in a...
4
by: Keithb | last post by:
A web site uses a SQL Server instance on another box and it takes a long time to establish a connection. Is there any way to make the web site stay connected to SQL server at all times, even though...
2
by: wajih.boukaram | last post by:
Hi I've been using asp.net for a couple of days now and i think I've gotten the hang of things I do have a problem when using HttpWebRequest: i request a page from a remote server and this...
4
by: boudrcj | last post by:
I'm having problems accessing elements of a child window even though both pages are in the same domain. The code works find if the two pages are from the same server, but not when I put them on...
0
by: service0086 | last post by:
Calvin Klein undergarments have a prominent presence on its website. This brand is quite popular among modern men. They are made from finest and softest fabrics to give that comfort you desire for....
0
by: service0031 | last post by:
Housekeeping is an interesting job or career where things are always changing, and even though you may work in a less than clean environment, you are required to always look clean and professional....
1
oranoos3000
by: oranoos3000 | last post by:
hi i read below text and i understand what say but i dont identify meaning of this setence preg_match may not fail on 4 and 5 octet sequences, even though they are not supported by the...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
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,...
0
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...
0
jinu1996
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 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.