473,722 Members | 2,338 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 4185
im*****@hotmail .co.uk wrote:
Daniel T. wrote:
>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.
The only way the vector can be corrupted is if you are dereferencing an
invalid pointer somewhere, or if you are going outside the bounds of
some other vector or array. The problem probably has nothing to do with
that particular vector at all. The problem is most assuredly not in the
vector code itself.

--
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 2 '06 #31
The only way the vector can be corrupted is if you are dereferencing an
invalid pointer somewhere, or if you are going outside the bounds of
some other vector or array. The problem probably has nothing to do with
that particular vector at all. The problem is most assuredly not in the
vector code itself.
I ran on a different machine and I get a different number assigned, it
looks more like a long int than the 32767 number I got in Linux. I
asserted the range and there is no problem until the error. I've only
got no other arrays (or vectors) and one pointer and it is a function
pointer, can I assert (or templatise) this too ?

It is along the lines of
typedef double fn(const double &x);
typedef fn *fnptr;

Oct 3 '06 #32
im*****@hotmail .co.uk wrote:
>The only way the vector can be corrupted is if you are
dereferencin g an invalid pointer somewhere, or if you are going
outside the bounds of some other vector or array. The problem
probably has nothing to do with that particular vector at all. The
problem is most assuredly not in the vector code itself.

I ran on a different machine and I get a different number assigned,
it looks more like a long int than the 32767 number I got in Linux.
I asserted the range and there is no problem until the error.
Then you are somehow putting that value into the vector, probably by
pushing an uninitialized variable into the vector.
I've only got no other arrays (or vectors) and one pointer and it is
a function pointer, can I assert (or templatise) this too ?

It is along the lines of
typedef double fn(const double &x);
typedef fn *fnptr;
Sure. Assign it the value "0" when you create the function pointer, then
assert( myFnptr != 0 ) before you use it.

--
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 4 '06 #33

Daniel T. wrote:
im*****@hotmail .co.uk wrote:
The only way the vector can be corrupted is if you are
dereferencing an invalid pointer somewhere, or if you are going
outside the bounds of some other vector or array. The problem
probably has nothing to do with that particular vector at all. The
problem is most assuredly not in the vector code itself.
I ran on a different machine and I get a different number assigned,
it looks more like a long int than the 32767 number I got in Linux.
I asserted the range and there is no problem until the error.

Then you are somehow putting that value into the vector, probably by
pushing an uninitialized variable into the vector.
I've only got no other arrays (or vectors) and one pointer and it is
a function pointer, can I assert (or templatise) this too ?

It is along the lines of
typedef double fn(const double &x);
typedef fn *fnptr;

Sure. Assign it the value "0" when you create the function pointer, then
assert( myFnptr != 0 ) before you use it.

--
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.
I found my mistake, it was a vector index problem, yes, indexing past
the end. I made a change and did not reflect the change across my app.
Better object design next time.

Oct 4 '06 #34
The STL vector does not throw any error if you index past the end, at
least not if you have reserved the space.

x.reserve(10);
x.push_back(wha tever);
...x[0] // OK
...x[1] // Also "OK", no error.

Oct 4 '06 #35
Greg wrote:
The STL vector does not throw any error if you index past the end, at
least not if you have reserved the space.

x.reserve(10);
x.push_back(wha tever);
..x[0] // OK
..x[1] // Also "OK", no error.
True, but x[1] is UB. x.at(1) will throw.
Oct 4 '06 #36

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

Similar topics

4
3404
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
3013
by: Alex Vinokur | last post by:
--------- #include <vector> using namespace std; struct Foo { Foo (int) {} }; int main () { vector<Foo> v1;
2
75791
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
4909
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
3446
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
2664
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
2566
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
11917
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
1984
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
8739
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9384
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
9088
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
8052
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
6681
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
5995
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
4502
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...
0
4762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2147
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.