vector

What is paging effect in C++?

I came across this as I was trying to learn array and vectors in c++. What is the "paging effect" mentioned in the post? Also, just to check my own understanding, I think vector uses more time is because of the dynamic memory allocation. Am I right? additional question: but with vector<int> arr( 10000 ) isn't there already enough memo...

How to set the length of a vector (in xna)

Hey, I'm wondering if there's a function out there to set the length of an XNA framework Vector3, like in c++ it would just be VECTOR.setLength( x ). Either that or the basic math to do it manually would be nice :) ...

Storing heterogeneous objects in vector with stack-allocated objects

Storing objects in heterogeneous vector with stack-allocated objects Hello, Say I have an abstract class CA, derived into CA1, CA2, and maybe others. I want to put objects of these derived types into a vector, that I embbed into a class CB. To get polymorphism right, I need to store a vector of pointers: class CB { std::vector <C...

iterate vector, remove certain items as I go.

I have a std::vector m_vPaths; I will iterate this vector and call ::DeleteFile(strPath) as I go. If I successfully delete the file, I will remove it from the vector. My question is can I get around having to use two vectors? Is there different data structure that might be better suited for what I need to do? example: using iterator...

Vertex shader world transform, why do we use 4 dimensional vectors?

From this site: http://www.toymaker.info/Games/html/vertex%5Fshaders.html We have the following code snippet: // transformations provided by the app, constant Uniform data float4x4 matWorldViewProj: WORLDVIEWPROJECTION; // the format of our vertex data struct VS_OUTPUT { float4 Pos : POSITION; }; // Simple Vertex Shader - carry ou...

How to have a vector of byvalue and use a vector of pointers in conjunction?

Hi! I have some vectors of class A objects: std::vector<A> *V1; std::vector<A> *V2; etc there is a function with a vector of pointers of A: std::vector<A *> *arranged; what I need to do is put the vectors from V1, V2 etc inside arranged without destroying them in the end, so I thought that a vector of pointers to those objects...

How do you std::vector in XCode + C++?

For various reasons (and I assure you they are valid, so no "use Cocoa" talk please), I must work with XCode, C++, OpenGL, OpenCL (with a little GLUT on the side) to rebuild a few graphics demos on Mac (coming from XP + Visual Studio 2005 development). The project was built as a Command Line Tool using "c++ stdc++". My Program.h file co...

why would std::vector max_size() function return -1?

I have a std::vector<unsigned char> m_vData; m_vData.max_size() always returns -1. why would that happen? ...

Vector initializing slower than array...why?

I tried 2 things: (pseudo code below) int arr[10000]; for (int i = 0; i < 10000; i++) { for (int j = 0; j < 10000; j++) { arr[j] = j; } } and vector<int> arr(10000); for (int i = 0; i < 10000; i++) { for (int j = 0; j < 10000; j++) { arr[j] = j; } } I ran both the programs and timed it using the "tim...

vector.resize function corrupting memory when size is too large.

what's happening is i'm reading encryption packets, and I encounter a corrupted packet that gives back a very large random number for the length. size_t nLengthRemaining = packet.nLength - (packet.m_pSource->GetPosition() - packet.nDataOffset); seckey.SecretValues.m_data.resize(nLengthRemaining); In this code m_data is a std::vector<...

getting an interval of a vector

I want to take an interval of a vector in Scheme. I know there is a procedure named vector->values, but seems like it returns each element separately, while I want to get the result as a vector. How can I achieve this? > (vector->values (vector 1 2 3 4 5) 0 3) 1 2 3 while I need: #(1 2 3) ...

Does changing vector size spoil iterators?

I found that this C++ code: vector<int> a; a.push_back(1); a.push_back(2); vector<int>::iterator it = a.begin(); a.push_back(4); cout << *it; print some big random number; but if you add a.push_back(3) between 3rd and 4th lines, it will print 1. Can you explain it to me? ...

Mono.Simd Vector3 (floats) missing?

Heya, I'm trying to use Mono's SIMD to handle coordinates(X,Y,Z) in my project, but I only see support for Vector2 and Vector4 types. Has anyone run into this before, and are there any workarounds? Thanks in advance. ...

Can you do Vector addition in Java, natively?

I Know there's a "Vector" class in java, but it seems to be just a simpler ArrayList type of deal, not an actual, mathematical Vector (as in a magnitude and a direction). Is there any way to do Vector manipulations (particularly addition) in Java? Or am I stuck on my own having to implement it or use a third party module? -Jenny ...

Passing std::vector for any type to a function

Given: template<typename T> class A { B b; std::vector<T> vec1; std::vector<T> vec2; } I'd like B to have a member function that fill() that takes a reference to those to vectors and fills vec2 with values of T depending on some information contained in b. One way of doing this is overloading fill() for each possible argument ...

Searching a C++ Vector<custom_class> for the first/last occurence of a value

Hi, I'm trying to work out the best method to search a vector of type "Tracklet" (a class I have built myself) to find the first and last occurrence of a given value for one of its variables. For example, I have the following classes (simplified for this example): class Tracklet { TimePoint *start; TimePoint *end; int angle...

Clojure: Call a function for each element in a vector with it index

Say I have a vector: (def data ["Hello" "World" "Test" "This"]) And I want to populate a table somewhere that has an api: (defn setCell [row col value] (some code here)) Then what is the best way to get the following calls to happen: (setCell 0 0 "Hello") (setCell 0 1 "World") (setCell 0 2 "Test") (setCell 0 3 "This") I foun...

Problems returning vector stack reference

Hello, I am working on an application that builds a vector of structs for items in a given directory and returns a reference of the vector for it to be read, I receive the following errors when attempting to compile the example code below: 1. 'class std::vector<indexStruct, std::allocator<indexStruct> >' has no member named 'name' 2. n...

Can I use C++ libraries in a C program?

I am writing a program in C, but I would like to use dynamic libraries like a vector. Is it possible to use C++ libraries in a C program? ...

java Vector and thread safety

I'm wondering if this code will do any trouble: I have a vector that is shared among many threads. Every time a thread has to add/remove stuff from the vector I do it under a synchronized block. However, the main thread has a call: System.out.println("the vector's size: "+ vec.size()); which isn't synchronized. Should this cause tro...