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 4181 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.
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; 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.
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.
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.
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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;
|
by: Alex Vinokur |
last post by:
---------
#include <vector>
using namespace std;
struct Foo
{
Foo (int) {}
};
int main ()
{
vector<Foo> v1;
|
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...
|
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
|
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
| |
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 )
|
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;
...
}
|
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).
|
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(); //
}
|
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: 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,...
| |
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...
|
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: 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: 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...
|
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: 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: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| | |