Evaluation order of new expression?
In the following code sample, do the C++ standard guarantee that '++i' is evaluated after the memory allocation (call to operator new) but before the call to X’s constructor? new X( ++i ) ...
In the following code sample, do the C++ standard guarantee that '++i' is evaluated after the memory allocation (call to operator new) but before the call to X’s constructor? new X( ++i ) ...
Recently, after being very tired, I wrote the following code: GLfloat* array = new GLfloat(x * y * z); Which, of course should have been: GLfloat* array = new GLfloat[x * y * z]; (Note the square brackets as opposed to the parenthesis.) As far as I know, the first form is not valid, but g++ compiled it. Sure, it spat out a complet...
The situation is: there is a file with 14 294 508 unsigned integers and 13 994 397 floating-point numbers (need to read doubles). Total file size is ~250 MB. Using std::istream takes ~30sec. Reading the data from file to memory (just copying bytes, without formatted input) is much faster. Is there any way to improve reading speed withou...
For some reason when I resize my OpenGL windows, everything falls apart. The image is distorted, the coordinates don't work, and everything simply falls apart. I am sing Glut to set it up. //Code to setup glut glutInitWindowSize(appWidth, appHeight); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA); glutCreateWindow("Test Window"); //In d...
I'm trying to understand what kind of memory hit I'll incur by creating a large array of objects. I know that each object - when created - will be given space in the HEAP for member variables, and I think that all the code for every function that belongs to that type of object exists in the code segment in memory - permanently. Is that...
I'm trying to create am immutable type (class) in C++, I made it so that all methods "aka member functions" don't modify the object and return a new instance instead. I'm running across a bunch of issues, but they all revolve around the reference types in C++. One example is when passing parameters of the same class type by reference:...
I have a function declared like so: template <typename T> T read(); and defined like so: template <typename T> T packetreader::read() { offset += sizeof(T); return *(T*)(buf+offset-sizeof(T)); } However, when I try to use it in my main() function: packetreader reader; reader.read<int>(); I get the following error from ...
I have a C++ function that I'd like to call using execvp(), due to the way my program is organized. Is this possible? ...
I've been comparing a STL implementation of a popular XmlRpc library with an implementation that mostly avoids STL. The STL implementation is much slower - I got 47s down to 4.5s. I've diagnosed some of the reasons: it's partly due to std::string being mis-used (e.g. the author should have used "const std::string&" wherever possible - ...
I ran into this supposed interview of Bjarne Stroustrup, the inventor of C++. http://artlung.com/smorgasborg/Invention_of_Cplusplus.shtml Stroustrup: Well, it's been long enough, now, and I believe most people have figured out for themselves that C++ is a waste of time but, I must say, it's taken them a lot longer than I thought it ...
Hello, I am working on a assignment where I am supposed to read a file and count the number of lines and at the same time count the words in it. I tried a combination of getline and strtok inside a while loop, which did not work. file:example.txt (the file to be read). Hi, hello what a pleasant surprise. Welcome to this place. M...
I need to build a custom simple non-authoritative caching DNS server in C/C++. Any guidance? Links? Samples? Thanks! ...
I have a priority_queue of some object: typedef priority_queue<Object> Queue; Queue queue; From time to time, the priority of one of the objects may change - I need to be able to update the priority of that object in the queue in an efficient way. Currently I am using this method which works but seems inefficient: Queue newQueue; whi...
I'm using libgc, a garbage collector for C and C++. To make STL containers garbage collectible one must use the gc_allocator. Instead of writing std::vector<MyType> one has to write std::vector<MyType,gc_allocator<MyType> > Could there be a way to define something like template<class T> typedef std::vector<T,gc_allocator<T> ...
This is prompted by a an answer I gave to a current question which asks about a generics library for C - the questioner specifically states that they do not want to use C++. My question to him and others who insist on using C is why do they do so when: C++ provides the specific features they are asking about Their C compiler is almost ...
Dear all, I have the following data as input (sorted by first column): foo 1 2 foo 3 3 bar 10 11 I want to create a Map of Vector with first column as key of the map such that we have: foo = {1,2,3,3} bar = {10,11} But why my code below doesn't work as expected? #include <vector> #include <map> #include <iostream> ...
I see functions/methods with a void return in the signature that have a return statement at the end of the function. What is the reason for this, and does this apply to other languages? For all I know, I can use return if I want to exit anywhere else but the end of the function. A C example: void funtion(void) { int x = 1 + 2; ...
I have an application that spawns multiple child processes. Before launching a child, I create stdOut and stdErr handles to a log file (for example, if I am about to launch procA, i create handles to logA.log). I set these handles on the child processes. By looking with ProcExplorer, I can see that each child process has handles to eac...
How do I detect with C# on Windows the moment when an external application is being launched? I tried the FilesystemWatcher which doesn't work because the file is not really changing. Also having a timer constantly check all the open processes might be a bit over kill. Is there any other way to do this? If not in C# is it possible to do...
Hi, I would like to know, where does java stderr standardly go? I know I can change the stderr using System.setErr, which 'Reassigns the "standard" error output stream.', but I dont know, which one is "standard". I would like to specify my question more: I have C++ library that I use in java (jni). The problem is that it appears that ...