I have a compressor that takes a file and first compresses it to an intermediate file "temp.lz", before compressing it to the final format. Immediately after that the file be removed by calling c's remove(char*). The problem I am afraid of is if calling this compressor from different processes is safe because of the intermediate file created which has the same name for all. (say temp.lz). Will I have problems when callinga sytem call from different process something like: system ("compress -i test.txt -o test.z") ?
I was thinking of rewriting the compressor to avoid the use of the temporary file but that is a bit awkward. I just need to use a temporary stream (file) different for each process to avoid race conditions.
The documentation of the class filebuf in the reference of cplusplus.com says:
Objects of this class may internally maintain an intermediate input buffer and/or an intermediate output buffer, where individual characters are read or written by i/o operations. These buffers are synchronized with the contents of the file once filled up, when explicitly requested to do so (sync), or when the object is closed.
Objects of this class may be explicitly made unbuffered by calling member pubsetbuf with both arguments set to zero (see member setbuf): Unbuffered file stream buffers perform the i/o operations directly on the file, without an intermediate buffer.
The C++ standard ensures that filebuf objects have an intermediate input/output buffer/s (i.e, the default constructor of the class filebuf creates the intermediate buffer/s)?
The standard C++ library only allows unbuffering filebuf objects (as the above quote says) but doesn't allow forcing filebuf objects to be buffered.
I have been seeying the concrete implementation code of the standard C++ library in my Windows Operating System (Windows 7 Ultimate 64 bits Service Pack 1) and it seems that fielbuf objects never uses intermediate input/output buffer/s, they use FILE streams of the standard C library instead to do the work. Are this FILE streams always buffered? If true, are they fully-buffered or line-buffered? what is the size of the buffers (perhaps macro BUFSIZ from <cstdio>)? and can I change this size?
I am worried about performance in reading and writing from/to files: if the default behaviour offers the best performance (perhaps if files are too large is better force buffering and choose a larger buffer size).
my doubt is :- in what data type the intermediate result of an expression is stored? like for expression 2+3*1/2 , i think the intermediate result for 1/2 is stored in the form 0.5 but for expression 2+3*1/100 , i think the intermediate result for 1/100 is stored in the form 0.01 so i am not sure if the compiler use dynamic type ie, changes with need. or it always stores in high precision like:- for 1/2 its 0.5000 and for 1/100 also 0.0100 or something like that.
this last few days I've been coding this one particular file
Hero.cpp
namespace Hero { namespace { // all data here } }
then the code grew a bit to about 700 line
Then now I want to implement hero skill system It needs the access to data inside the unnamed namespace where I put just about everything.. but it's unnamed namespace, it's only valid within one file and I should hide all that data from Hero interface in Hero.h How should I do this ?
I'll just tell you in short how my Problem looks like: I should implement a New Class in a SourceCode i didnt write myself. The source code is extremely sized (i think approx >100.000 Lines of Code), so i dont want to change too much in it in order to get my Implementation done.
MY problem looks simplicified like that: Starting from 3 classes and my new class the pseudo-code looks like that:
So, i need Parameters from 3 different classes to insert in my NewClass. The 3 Classes dont know anyting about each other. So, i need to implement a Class-Instance from Type NewClass which is known by the other 3 Classes. I did solve it in this way:
I just wrote a headerfile with a class-instance which is getting included by the other 3 Classes. So they all know the same Instance and writing their Parameters into it. Is this a decent solution or could it happen to get bugs/ logical mistakes with it?
I need my Unix program to generate a directory with a format like this: "hinesro.<pid>". I have some code that mostly works, except for the directory ends up with a question mark on the end, like this: "hinesro.12345?". I need it to just display the directory without this question mark. Here is my code:
Code:
// Using headers sys/types.h, sys/stat.h, unistd.h, and stdio.h int pid = getpid(); char prefix[] = "hinesro."; char fileName[0]; sprintf(fileName, "%s%d ", prefix, pid);
Suppose multiple threads are are trying to insert into a STL Map, both are trying to insert with same key. As per my understanding it will not cause any issue till you invalidate the iterator. Here as per me it will not invalidate the iterator.
When i am entering single character instead of 'miz' then it is working great. But when i am using multi character like 'miz' it is showing error output. i did this program with c++ it is working but not working in c.When i am running this program it is showing {warning] multi character constant.
Code:
#include<stdio.h> #include<string.h> main() { char a; printf("Please Enter your First Name: "); scanf("%s",&a);
i want to make a two-dimensional array that is consisted by objects but i dont want to initialize the objects when i make the array.. i just want to make an array that each of his "cells" has the size of an object.For example,
class Human{ int hm=5; ... };
and now i want to make a two dimensional array that each "cell" has the size of an Human but not a Human itself.
So basically, I started out with each wizard == 1 winform, but then I found another way to do it by making the content of each wizard step a user control, then say, on initial deployment, it load usercontrol1, then when i click next, the panel hide usercontrol1 for usercontrol2 and so forth. Would it be feasible to create all usercontrols (all the wizard step) and add them in an array, then i can load them by index?
I am new to Path Finding so I just know BFS, DFS, Djisktra, and Basic A*
I've searched for a few multi agent pathfind paper here and there. But I can't seem to understand them..
I am path finding in a grid map, 4 ways neighbor movement
My map isn't so big it's 300 x 300 up to 400 x 400
Most of the map is open space, I would say that at worst case 4/5 of the map is open space.
And there is probably around 100 agents.
I've tried running BFS 100 times and it takes around 200ms on average
Changing BFS to A* which I am thinking right now will definitely cost lesser time
But are there better ways in doing this ? and also Does running Single Agent A* multiple times doesn't cause problem for other agent ? perhaps causes deadlocks ? ( Considering that the path that have been determine for agents before the current searched is considered blocked )
I recently wrote a perceptron that determines whether a point is above or below a line. I'm trying to write a multi-layered ANN so I can use it to solve more complicated problems than "is this point above/below this line?"
Here's my source code: [URL] ....
Considering that a A XOR B is simply (NOT A AND OR (A AND NOT , and both of those are linearly separable...
I tried to make the output look like this --> ENTER YOUR NAME:Victor Collin ENTER YOUR COURSE:BSComSci but everytime I entered my name the course went to the next line.How to make the output in the same?
The Connection class holds the Database Connection ODBC Handle.
The Statement class holds the Statement Handle, there can be multiple per Connection. It is made and destroyed each time a query must be done on the DB.
Now I'm just wondering.
I have a multithreaded application.
Is keeping one Connection for one DB enough for the whole application? Where the different threads will make Statements based on that one Connection.Or is it better to keep a Connection per thread?
I want to have a multi user chat over TCP/IP. I already have the code for both the server and the client and so far I am able to send messages from the client to the server. Now I want to make it a multi user chat. I am executing the codes using Visual studio's Command prompt(not Windows Command Prompt). I have read somewhere that we have to use select() function.
I have to delete an object at a time that I don't know it's held by another thread(s) or not. For example
static void foo(CLASS* ref){ pthread_mutex_lock(&l);//[POINT-A] //using ref //do something thread safe pthread_mutex_unlock(&l); delete ref;// how can I find out there is no any thread held at [POINT-A] }
I need to create subfunctions to do basic Matrix mathematics (addition, subtraction, etc.) I need to be able to pass bot of my Matrices to subfunctions. I started with the addition sub function and I cant get the code to run. I keep getting expected primary-expression before ']' token error for line 75.
#include <iostream> #include <stdio.h> using namespace std;
I have always written like a>='0'&&a<='9'&&a>='a'&&a<='z' in loops etc, but no more. Basically add whatever you want to condition, and if you want point a to point b just separate them with a '-' sign. Simply
I am working on the game of fifteen.Yes this is home work. I was wondering if it is possible to save the indexes of an element in a two dim array. I need to find the position of the space in the two dim array save it, find the position of the tile which is passed in as an int and swap the two if they are adjacent. Here is my code
Edit: I can do this by saving i and j in separate int variables but is there a more elegant way of doing this
int board[MAX][MAX]; void init(); void swap(int* lhs, int* rhs);
I'm trying to union eleven tables to call out data. Parent table is 'Events', child tables are 'SR1Laptimes', 'SR2Laptimes' and so on (there are ten SR... tables). Primary key in all tables is EventName. Parent/Child relationship is Events.EventName/SR1Laptimes.EventName etc All tables that start with SR have the same Schema. I'm trying to call out MIN(Q1) across all table but first need to Union them I believe. Here is my code.
myCommand.CommandText = "SELECT MIN(Q1), MIN(Q2), MIN(Q3), MIN(Q4), MIN(LaptimesMinutes), MIN(LaptimesSeconds) FROM (SELECT * FROM Events UNION ALL SELECT * FROM SR1Laptimes UNION ALL SELECT * FROM SR2Laptimes) WHERE (Events.Track = @track) AND (Events.Number = @number) AND (Events.Rider = @rider)"; myCommand.Parameters.AddWithValue("@track", analysisTrackComboBox.Text); myCommand.Parameters.AddWithValue("@number", analysisNumberComboBox.Text); myCommand.Parameters.AddWithValue("@rider", analysisRiderComboBox.Text);