|
Hi All,
I am having an application where a structure will be directly written into HDD in binary format at a particular time interval.
But if PC gets turned off due to some abnormal problems, during file write, after the next restart the entire file has only 0's. it is getting corrupted.
How can i avoid this problem (apart from taking backup and restore in case of corruption).
Any help would be appreciated.
Thanks.
Selva
|
|
|
|
|
If the file is very big one way could be dividing the data to be written in small packets, opening file, saving a packet, closing file and repeating.
It will be slower, but closing the file sometimes during the process should make to save the already sent content, you will lose only the packet you are sending in the moment the computer crashes.
BTW It is just a guess, never tried it.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
An alternative to Nelek's suggestion of Open, Write, Close is to call a Flush after every write.
There always is a window of opportunity for disk files to get trashed. Even using the suggestions you've received, there is a chance that the machine will power down before the disk cache is written to disk. The only way to make that window smaller is to use something like the commit function, which is a pretty low level C function. It instructs the OS to issue the actual write commands to the disk. The one case you can't guard against is someone powering off a machine while the actual physical write is in progress, but from what little you said, it sounds flush should give you what you need.
Judy
|
|
|
|
|
SelvaKr wrote: after the next restart the entire file has only 0's. it is getting corrupted.
I sense that you are after a way of writing mission critical data in an guaranteed safe way, so that integrity is maintained, even during a powerfailure halfway tru the write. I have done quite a bit of research on this,and came to the following design conclusions.-
1. It is Not possible to guarantee a successfull write under above circumstances
2. It is possible as Second Best, to maintain a consistent state. This means that under such circumstances, the transaction is either completed in full, or you are returned to the state prevailing before the transaction commenced. This is not a guaranteed write, but, atleast, you have not the corruption of a partially completed transaction.
My system requires two identical file sets, marked Primary and Alternate.
There is also a single third file, the State file, which holds only One Byte. This Byte assumes one of the following Values:-
STATE_NORMAL, STATE_MOD_PRIMARY, STATE_MOD_ALTERNATE.
When we start, Both Primary ad Alternate Sets are Identical.
Step 1:
The Write Operation commences by opening the State File, and Writing STATE_MOD_PRIMARY to it, after which it is closed. This indicates that the Primary Set is now entering into a potentially unstable State, but the Alternate holds a consistent backup.
Step 2:
Carry Out All your Writes to the Primary Set. When the Write is Completed, Close All Files.
Step 3:
Open the State File, and Write STATE_MOD_ALTERNATE to it, after which it is closed. This indicates that the Alternate Set is now entering into a potentially unstable State, but the Primary Set holds the New Dataset.
Step 4:
Delete All Alternate Files, and replace them with copies of the Primary Set.
Step 5:
Open the State File, and Write STATE_MOD_NORMAL to it, after which it is closed. This indicates that the Data Set is Once again in a Stable state.
When your Excecutable starts, it must investigate the FileTime's of the State File, the Primary Set, and the Alternate Set. A Prima Facia Consistent state is indicated by FileTime(Primary)<filetime(alternate)><filetime(state) but:="" see="" below,="" this="" relation="" state="" may="" not="" hold="" if="" you="" breakdown="" again="" during="" recovery.<br="" mode="hold">
Another Consistency test is that the State File contains STATE_MOD_NORMAL
If any of this fails, you can figure out from the above description, where things went wrong, and what todo. The two Possibilities here are RollBack: Copy the Alternate to the Primary, or, Complete: Copy the Primary to the Alternate.
I have developped a custom API to implement the above.
It works with:
HFILESET OpenFileSetForWrite(DWORD Flags,int NrOfFiles, LPCSTR[] FileNames);
ERRCODE WriteFileSetFile(LPCSTR Buf,int size,int count,HFILESET hfs,int FileIndex,int* WrSize);
ERRCODE CloseFileSet(HFILESET hfs);
Another aspect is that I included a 64 byte code in the State File to help the App recover to where things went wrong. If at all posible the user is brought to the starting screen of the aborted transaction.
Note.: Powerfailures and Hardware failures(broken tracks in boards etc) are notoriously hard to simulate. It is essentially 'Out of Spec Behaviour. What attracted me to your question was that you suggest to have a hardware way of testing your code. Could you suggest to me how to test this. I used a method involving a USB Device which was fired via a (semi)random timer, triggered by the WriteFileSet() funtion, to cut the Power to the PC. What did you use to test your software.
Regards,
Bram van Kampen
|
|
|
|
|
Hello all,
I have a code which is compiling in multibyte character set but giving some errors in unicode character set like:
1) error C2664: 'CStdioFile::Open' : cannot convert parameter 1 from 'char[260]' to 'LPCTSTR'.
2) error C2664: 'GetTempPathW' : cannot convert parameter 2 from 'char [260]' to 'LPWSTR'
3) error C2664: 'CStdioFile::Open' : cannot convert parameter 1 from 'char [260]' to 'LPCTSTR'
4) error C2664: 'void ATL::CStringT<BaseType,StringTraits>::Format(const wchar_t *,...)' : cannot convert parameter 1 from 'const char [3]' to 'const wchar_t *'
can anybody please help me in this....
Thanks in advance
|
|
|
|
|
I think ther first three ones can be resolved by type-converting.
(4) should use _T("") macro or L prefix.
|
|
|
|
|
You can either change array declarations (i.e. TCHAR instead of char ) and then assign them consistently or apply string conversions http://msdn2.microsoft.com/en-us/library/87zae4a3(VS.71).aspx[^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Without seeing the code that is causing these errors, it's difficult to say exactly the best way to solve them.
For the CStdioFile.Open, if you are using something like
myFile.Open("test.txt", CFile::modeCreate); you could just change it to
myFile.Open(_T("test.txt"), CFile::modeCreate);
The same may be try for the ATL::CStringT problem. The following code could cause the error:
CString myString("Test"); Again, this can be fixed by using
CString myString(_T("Test"));
The advantage is that this will work with either MBCS or Unitcode builds.
Hope that helps.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
My OS is Windows XP professional. I set my location to US and Language to English.
So,when I want to print some no English words like Chinese,Japanese,I would failed. For example
wchar_t *s = L"??";//?? are some non-English words,it did not display rightly
int err = wprintf(s);//operation failed,err = -1,
wcout<<s<<endl;//no output on the screen
I want to know why the printing operation would be failed.
Someone would advise me to set my system's default location and language,but,if a system with US location and open a file with such non-English file,how should it to display the content?
Thanks.
modified on Friday, December 07, 2007 2:27:13 AM
|
|
|
|
|
The problem is that a computer with the language you are talking about, created the file with it's own charsets and fonts. Codes for these characters has a glyph in that font but they don't in your current font or they even don't exist in your current character set. Some info about these terms[^]
So here you have two options:
1. The hard and right way: define your application to use Unicode. You shall take care of all strings and all functions that use strings since each character will take (at least) two bytes instead of usual one byte. You also should take care of all functions that ask you to enter Size or Length of the string which will be different. I'm still not 100% sure this helps when printing, but as softwares like MS Office Word can do the job, they'll do it this way probably.
2. The easy way(might not help for printing): Install the language in your computer and ask windows to select it as your default language for NON-UNICODE applications: Go to control panel->Regional and language options, select Advanced tab and check if you can find the language you want in the combo box under 'Language for non Unicode programs' if not go to Language tab where you should select if it's an East Asian or if it has complex scripts, then apply and return back to Advanced. Find the language and select it. Apply changes and your application should not show those characters any longer, but I doubt it fixes print problem. Also note that in VC6 You have to right click on dialogs in your resource view and choose [Neutral] instead of default English language if you want to show characters truely on screen.
// "In the end it's a little boy expressing himself." Yanni
while (I'm_alive) { cout<<"I love programming."; }
|
|
|
|
|
Yes,I agree with you.
In fact,my problem is that,when I reading the ID3v1 text tags from a .mp3 file.There is no enough information about characterset of the text string coding.So,if a text string is non-English encoded,the reading and displaying would failed.A text string in ID3v1 is a 30 characters(also is 30 bytes) long array.I read it one by one,and call MultiByteToWideChar function to convert the string into Unicode string,but the converted Unicode string is incorrect.
Thanks
|
|
|
|
|
Please do some tests to find out how you need to act:
Use debug window to see the memory address of the variable that you use to store the id3 tag. Also try changing debug option that says 'Use Unicode string'. It's likely that debug window shows true characters and that shows you to use Unicode.
Make sure your dialogs where you display the text on them have neutral language set. Try displaying data in GDI controls like Static or TextBox instead of directly drawing them on the DC.
Try softwares that display these data, like WinAmp or JetAudio, if you have access to them and check to see if they can display the tag truely.
If you noticed any difference, you can find a true solution to the problem, or at least you'll have a clue to start from.
// "In the end it's a little boy expressing himself." Yanni
while (I'm_alive) { cout<<"I love programming."; }
|
|
|
|
|
Hello,everyone
I'm using vc6.0, using ms datagrid control 6.0
I want to change the color of the current row in datagrid.
Changing the current row's font or other things to make the row selected noticeable is also OK!!
Thanks!!
modified on Monday, December 10, 2007 7:39:03 PM
|
|
|
|
|
hi all
Currently i am creating a window mobile program using visual c++. wanted to find out what is the code to redirect my current dialog to another new dialog in 2 seconds.
Thanks for your help. Appreciate your help guys.
|
|
|
|
|
what about putting timer in your application, which open new dialog after 2 seconds!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You/codeProject$$>
|
|
|
|
|
Hi all,
I'm working with a map to store a string, int pair. I want to make my code more clear. So I'm try to define my map in a common place and use to store data on it. So where should I declare the map.
I've try to define in the class definition file(class header file), but in the data insertion statement I got the following error.
<br />
error C2678: binary '[' : no operator found which takes a left-hand operand of type 'const std::map<_Kty,_Ty>' (or there is no acceptable conversion)<br />
I've declared the map as follows,
map<string, int=""> data_map;</string,>
How can I solved this.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Firstly map not declared as
map data_map;
if you have to store an int & a string inside the map then declaration will be like this: -
map< int,std::string > data_map;
In this the integer filed will be your primary field and corresspoding to which you get the data.
Regards,
Pankaj Sachdeva
There is no future lies in any job but future lies in the person who holds the job
|
|
|
|
|
Oops,
Really sorry about that. Miss the middle part of the code, may be because of the code tags.
Its like this,
map<string, int=""> data_map
I appreciate your help all the time...
Eranga
|
|
|
|
|
Eranga Thennakoon wrote: Really sorry about that. Miss the middle part of the code, may be because of the code tags.
Oops you did it again!
Use the pre-Tag to enclose the code or use the < > tags instead of the one on your keyboard.
You'll find them below the text editor when writing the message!
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all. Douglas Adams, "Dirk Gently's Holistic Detective Agency"
|
|
|
|
|
Karismatic wrote: Firstly map not declared as
map data_map;
His map is declared as:
map<string, int=""> data_map;
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi Experts,
I want to create a project that has two view :
First view displays the tree view of all files and folders and
Second view displays the corresponding file click on the folder of first view.
My mean to say like a Windows Explorer view.
How can I achieve it.
Thanx in advance.
|
|
|
|
|
First, the division is to be made through SplitterView, the left side as CTreeView and the right side as CListCtrl or CListView in report mode
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
Does anyone know where the demo and zip files from this google cache are ? The links off of the cache are broken.
http://64.233.169.104/search?q=cache:_hGEheYkd6YJ:www.codeproject.com/debug/LibView.asp+view+.lib+function&hl=en&ct=clnk&cd=1&gl=us&client=firefox-a[^]
On the google cache html there is some code, but I'd prefer to download the original demo, since I'm not entirely sure how much code is missing from the excerpt.
The motive:
My task is to make arbitrary c++ source code trees available to .NET. I created a program to scan the header files and create a SWIG interface file to input into SWIG which generates pinvoke signatures (in a large C++ file (150000 lines)) for the libraries. The problem is, sometimes the header files contain signatures that didn't get implemented in the libraries and therefore I get a bunch of linker errors.
So in order to workaround this, I would like to scan the .lib files for function definitions and then compare against header files in order to determine what's been implemented (without having to do it manually - these source code trees are huge).
Thanks for your help.
|
|
|
|
|
|
Im posting this here in the hopes of a quicker answer (as opposed to the Graphics forum).
I've been playing around with DirectX in C# for quite some time now with success. All the tutorials in the DXSDK9.0 run fine for C# and VB.Net.
I want to learn how to use DirectX in C++, but when I try and run any C++ example I get the below errors...
1. Error LNK2019: unresolved external symbol _Direct3DCreate@4 referenced in function “long_cdecl InitD3D(struct HWND__*)”(?InitD3D@@YAJPAUHHWD__@@@Z)
2. Fatal error LNK1120: 1 unresolved externals
These errors were generated when I tryed to run the very first tutorial (initialise a DirectX device).
I figure there maybe a header file I need to move somewhere.
Has anyone run into this problem before, and/or knows how I could fix it?
Kind Regards,
Mark.
|
|
|
|
|