473,698 Members | 1,902 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

bus error, resize vector

I get a bus (or is it buss) error when I resize a vector

typedef std::vector<dou bledblvec;
n = 127;
dblvec rv;
rv.resize(n); // error happens here

Any clues ? I can post more info if required ?

Sep 29 '06
35 4179
im*****@hotmail .co.uk wrote:
>Now change all the op[] calls with at(). If you use all vectors, you can
do that with a global replace of '[' with "at(" and then globally
replace ']' with ")".

Do you mean change x[i] to x(i) or something else ?
He meant with:

std::vector<int vec;
int index = 42;

Change all occurences of
vec[index]
to
vec.at(index)

The at function does the same thing as operator[] but will throw an
exception when the index is out of bounds.

--
Thomas
http://www.netmeister.org/news/learn2quote.html
Sep 30 '06 #21
That will likely find your error real quick.

OK, yes it does not get far atall, I get an error (but no hint as to
what variable or part of the program)

terminate called after throwing an instance of std::out_of_ran ge
what(): vector::_M_rang e_check
Aborted

Oct 1 '06 #22
im*****@hotmail .co.uk wrote:
>That will likely find your error real quick.

OK, yes it does not get far atall, I get an error (but no hint as to
what variable or part of the program)

terminate called after throwing an instance of std::out_of_ran ge
what(): vector::_M_rang e_check
Aborted
Hint: run the program in a debugger. Then get a calltrace from the moment
when it aborts. This should tell you which function has the bug.
Best

Kai-Uwe Bux
Oct 1 '06 #23
im*****@hotmail .co.uk wrote:
>That will likely find your error real quick.

OK, yes it does not get far atall, I get an error (but no hint as to
what variable or part of the program)

terminate called after throwing an instance of std::out_of_ran ge
what(): vector::_M_rang e_check Aborted
You are trying to access an array out of its bounds. Either use a
debugger and have it break on all exceptions, or go into the code at the
last place you know worked (based on how much output you got before it
crashed) and start looking at all the "at()" calls. The value passed
into one of them is too large.

--
There are two things that simply cannot be doubted, logic and perception.
Doubt those, and you no longer*have anyone to discuss your doubts with,
nor any ability to discuss them.
Oct 1 '06 #24

Daniel T. wrote:
You are trying to access an array out of its bounds. Either use a
debugger and have it break on all exceptions, or go into the code at the
last place you know worked (based on how much output you got before it
crashed) and start looking at all the "at()" calls. The value passed
into one of them is too large.
I put a std::cout and std::endl in the template ( [] function) and I
got a compiler message even though I included iostream. Why do I need
to change to at() calls if these are in the template ?

Oct 1 '06 #25
In article <11************ **********@m73g 2000cwd.googleg roups.com>,
im*****@hotmail .co.uk wrote:
Daniel T. wrote:
You are trying to access an array out of its bounds. Either use a
debugger and have it break on all exceptions, or go into the code at the
last place you know worked (based on how much output you got before it
crashed) and start looking at all the "at()" calls. The value passed
into one of them is too large.

I put a std::cout and std::endl in the template ( [] function) and I
got a compiler message even though I included iostream. Why do I need
to change to at() calls if these are in the template ?
In your code you have something like:

myVec.at( i )

In the line before that, put:

assert( i < myVec.size() );

Do that everywhere you are using "at()".

When the code breaks, it will tell you what file and line number in that
file the problem is located at.

--
There are two things that simply cannot be doubted, logic and perception.
Doubt those, and you no longer*have anyone to discuss your doubts with,
nor any ability to discuss them.
Oct 1 '06 #26
OK, I got this debug template working. It would be nice to see the
variable name of the offending object.

Oct 1 '06 #27

<im*****@hotmai l.co.ukwrote in message
news:11******** **************@ e3g2000cwe.goog legroups.com...
OK, I got this debug template working. It would be nice to see the
variable name of the offending object.
Is this in response to something? What "debug template"? Do you have a
question?

Please provide some context in your responses, by quoting the relevant
portion(s) of what you're responding to. This isn't a chat room, and it's a
pain in the butt to try to go back and forth between messages to see where
the conversation has been going. Check out other posts here (such as this
one :-)) to see what I mean.

Thanks,
-Howard

Oct 2 '06 #28
Is this in response to something? What "debug template"? Do you have a
question?

Please provide some context in your responses, by quoting the relevant
portion(s) of what you're responding to. This isn't a chat room, and it's a
pain in the butt to try to go back and forth between messages to see where
the conversation has been going. Check out other posts here (such as this
one :-)) to see what I mean.

Thanks,
-Howard
It is one of these snazy gadgets (don't correct this code, as I pasted
from another message)
essentially..

#include <vector>

template < typename T >
class Vec : public std::vector< T {
public:
Vec() { }
Vec( int s ) : std::vector<T>( s) { }
T& operator[](int i) { return this -at(i); }
const T& operator[](int i ) const { return this -at(i); }
};

This was something I abandoned, but I got it working. So I based my
vectors on this now, for debugging.

typedef Vec<doublevecdb l;
typedef Vec<vecdblmatdb l;

Oct 2 '06 #29

Daniel T. wrote:
In your code you have something like:

myVec.at( i )
No because I got that template working, see my reply to Howard. (but
you know the one)
In the line before that, put:

assert( i < myVec.size() );

Do that everywhere you are using "at()".

When the code breaks, it will tell you what file and line number in that
file the problem is located at.
That won't do it, I already output at every place I write to these
vectors and there is no indication that I am assigning 3276..whatever
(actually 2^31 - 1 or such like).
Something else is corrupting this vector.

Oct 2 '06 #30

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

Similar topics

4
3398
by: Peter Mrosek | last post by:
Hello, I have the following declaration in an header file (abbreviated version): typedef struct { unsigned char rgbBlue; unsigned char rgbGreen; unsigned char rgbRed; unsigned char rgbReserved;
9
3012
by: Alex Vinokur | last post by:
--------- #include <vector> using namespace std; struct Foo { Foo (int) {} }; int main () { vector<Foo> v1;
2
75789
by: B_Love | last post by:
Hey! When trying to compile the code for a ordered vector class I get the following error: undefined reference to `WinMain@16' Anyone have any idea what I might be doing wrong? I've been through this code multiple times and have no idea what would cause an error like this, I've never seen one like it before. Any help would be greatly appreciated. The class is supposed to be able to create a sorted list of vectors of type Object. If an...
8
4898
by: Jason Heyes | last post by:
Does the STL have a function like this one? template <typename T> void remove(std::vector<T> &v, std::vector<T>::size_type index) { std::swap(v, v.back()); v.resize(index); } Unlike std::vector::erase, it calls T::operator= only three times no matter
2
3444
by: mj | last post by:
Hi, I recently have found it necessary to move from fortran to c++ for scientific programming... I'm working on a program that needs to resize a 2d vector of vectors within a function... This variable "tri" is an input arg to my function using the syntax: function(vector<vector<int> >& tri) The problem occurs when the tri 'matrix' is resized to triple or
2
2661
by: mrbrightsidestolemymoney | last post by:
Hi, I'm having a problem resizing a (very big) nested vector. It's not the most streamlined piece of code ever but I need this array to avoid having to recalculate the same quantity millions of times! The (relevant) snippets of code are below : since it's relevant though L=28,T=96 (so TasteProps weighs in at a hefty 8*96*28*28*28*96=1,618,477,056 doubles )
18
2561
by: imutate | last post by:
I have an integer variable and I am testing it as follows #define NULL_VAL -1 ... if (x.id != NULL_VAL) { std::cout << x.id << std::endl; ... }
17
11913
by: toton | last post by:
Hi, I am using a vector to reserve certain amount of memory, and reuse it for new set of data, to avoid reallocation of memory. so the call is something like vector<my_datav;///the temporary storage. v.reserve(300); ///at max I have 300 data. now, my_data doesn't have a default ctor (as it doesn't have a default state).
2
1981
by: nikiplos | last post by:
Hi, all... I have a problem when trying to reallocate a vector for a second time inside a loop. The order is somelike: for (n=k; n<L; n++) { vector.resize(n, (long) 0); ... vector.clear(); // }
0
9155
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9018
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 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...
0
8858
tracyyun
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...
0
7711
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6517
isladogs
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...
0
5859
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();...
0
4614
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2322
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1997
bsmnconsultancy
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...

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.