c++

Random-access container that does not fit in memory?

I have an array of objects (say, images), which is too large to fit into memory (e.g. 40GB). But my code needs to be able to randomly access these objects at runtime. What is the best way to do this? From my code's point of view, it shouldn't matter, of course, if some of the data is on disk or temporarily stored in memory; it should ...

gcc reverse_iterator comparison operators missing?

I am having a problem using const reverse iterators on non-const containers with gcc. Well, only certain versions of gcc. #include <vector> #include <iostream> using namespace std; int main() { const char v0[4] = "abc"; vector<char> v(v0, v0 + 3); // This block works fine vector<char>::const_iterator i; for (i = ...

How can I determine distance from an object in a video?

I have a video file recorded from the front of a moving vehicle. I am going to use OpenCV for object detection and recognition but I'm stuck on one aspect. How can I determine the distance from a recognized object. I can know my current speed and real-world GPS position but that is all. I can't make any assumptions about the object I'm...

How to compile this on Windows

Ok. I am trying to compile the following application on Windows (Segmenter, see step 3). I checked out the source and changed the references so that'd all be good. It's basically a one file app, with a reference to ffmpeg. The makefile reads: gcc -Wall -g segmenter.c -o segmenter -lavformat -lavcodec -lavutil -lbz2 -lm -lz -lfaac...

Crash, while printing contents of linked-list

Hello, I'm having some trouble printing out the contents of a linked list. I'm using an example code that I found somewhere. I did edit it a bit, but I don't think that's why it's crashing. class stringlist { struct node { std::string data; node* next; }; node* head; node* tail; public: BOOLEAN append(std::string ...

Design options for references into a thread safe cache when evicting older entries

I'm trying to design a simple cache that follows the following rules: Entries have a unique key When the number of entries in the cache exceeds a certain limit, the older items are evicted (to keep the cache from getting too large). Each entry's data is immutable until the entry is removed from the cache. A 'reader' can access an entry...

How to create something like firefox's bookmark sidebard in Visual Studio 2008 C++ project?

I have visual studio 2008, and want to build an GUI application that on the left side has a frame that can be minimized like the firefox bookmark sidebar. So my questions are: 1) What type of project do I need? 2) What controls actually make up the sidebar. 3) What do I make the main frame so that I can resize it when the sidebar is op...

How to write a wrapper over functions and member functions that executes some code before and after the wrapped function?

I'm trying to write some wrapper class or function that allows me to execute some code before and after the wrapped function. float foo(int x, float y) { return x * y; } BOOST_PYTHON_MODULE(test) { boost::python::def("foo", <somehow wrap "&foo">); } Ideally, the wrapper should be generic, working for functions and member fun...

What do C and Assembler actually compile to?

So I found out that C(++) programs actually don't compile to plain "binary" (I may have gotten some things wrong here, in that case I'm sorry :D) but to a range of things (symbol table, os-related stuff,...) but... Does assembler "compile" to pure binary? That means no extra stuff besides resources like predefined strings, etc. If C co...

What's the best way to force the user of a C++ function to acknowledge the semantic meaning of parameters that are numerical constants?

I'd like to write function interfaces that force the user to acknowledge the semantic meaning of built-in constants. For example, I'd like to take void rotate(float angle); // Rotate the world by an angle in radians. and change it to void rotate(Radians angle); Am I right in believing that the problem with making a Radians class is...

How do I add an object to a vector<const Obj&> ?

I am not sure why this doesn't compile: std::vector< const Obj& > myVector; void foo(const Obj& obj) { myVector.push_back( obj ); } Sorry, a bit of additional info on what I'm trying to achieve: I can't change the signature of foo without breaking an interface, but I just want to hang onto the Objects that get passed through...

What is the cleanest way to create a timeout for a while loop?

Windows API/C/C++ 1. .... 2. .... 3. .... 4. while (flag1 != flag2) 5. { 6. SleepEx(100,FALSE); //waiting for flags to be equal (flags are set from another thread). 7. } 8. ..... 9. ..... If the flags don't equal each other after 7 seconds, I would like to continue to line 8. Any help is appreciated. ...

std::map inizialitazion (only one time)

I have a function that translates data using std::map struct HistoParameter { int nbins; float first; float last; HistoParameter(int _nbins, int _first, int _last) : nbins(_nbins), first(_first), last(_last) {}; }; HistoParameter* variable_to_parameter(char* var_name) { std::map<const std::string, HistoParameter*> hp; h...

g++ alignment problem

I have the following code: #include <stdio.h> int main(void) { int x __attribute__ ((aligned (16))) = 0; printf("%lX\n", &x); return 0; } Compiling and running this code using mingw32-c++.exe (GCC) 3.4.5 (mingw-vista special r3) prints 0x22FF24 which is 0b1000101111111100100100. Compiling and running this code using g++ ...

is there something like .dll or .so,but crossplatform?

is there something like .dll or .so,but crossplatform? ...

Unknown error in array initilization

I was trying to make a Intel 8080 CPU emulator (then I'd like to emulate Space Invaders, which use it). I coded nearly complete implementation of this CPU (thanks to MAME and Tickle project (mostly) ;) ) except undocument instructions (0x08, 0x10, 0x18, 0x20, 0x28, 0x30, 0x38, 0x0CB, 0x0D9, 0x0DD, 0x0ED, 0x0FD). I've have only problems...

Makefile works %.c, does not work %.cpp

I have a set of makefiles I use to build a 'big' C project. I am now trying to reuse some in my C++ project and have run into this headache that I just cannot figure out. The makefile looks like this SOURCES = \ elements/blue.cpp # Dont edit anything below here VPATH = $(addprefix $(SOURCE_DIR)/, $(dir $(SOURCES))) CXXFLAGS = $(OPT...

Apache have shared objects for both windows and linux.How do they do it?

Apache have .so modules for both windows and linux.How do they do it? ...

VTK window thread from main thread, C++

hello, I am just learning VTK (and C++ GUI programming) and have hopefully simple question. The main application launches rendered window at some point in application. Would like to be able for the main thread to continue, while VTK window is displayed. Is there a particular method to launch VTK window as a thread? My environment is L...

Fast cross platform algorithm for reading/writing file in C++

I want to pose a seemingly simple question that i can't find the answer nowhere. Is there a FAST modern algorithm for file input and/or output that can be compiled with all standard compliant C++ compilers and works for all operating systems without the requirement of external libraries ? i have found that the fastest way is to use mem...