Adding QByteArray
-
Obviously, what you given is a runtime error instead of compile errors.
If you are sure that above example will cause this exception under your environment, please debug it first and tell us which line trigger the exception.
-
I am writing the binary files using following method.
@
//....
typedef std::basic_ofstream<unsigned char, std::char_traits<unsigned char> > uofstream;
uofstream op(filename, ios::out | ios::binary);
op.write(size, 5);
op.write(RGrBl, widthheight3);
op.write(a,widthheightdifference);/difference is int size[4]
op.close();
@I want to add the values at each BYTE in the files created by above function. I am unable to write it because of exception at run time saying bad memory allocation, and referring to mlock.c
I just want to add the hex values at all the bytes but I am getting exceptions at time saying bad memory allocation and referring to mlock.c. I am using
@
//x and y are read from files created using the above
QByteArray alpha; for(int k=0;k<qMin(x.size(), y.size());k++){ alpha.append(x[k]-y[k]); } qDebug()<<z.toHex();
QByteArray beta; for(int j=0;j<qMin(x.size(),alpha.size());++j) { alpha.append(x[j]+z[j]); } qDebug()<<beta.toHex();
@What could be wrong in this ?
Thanks[EDIT: code formatting, Volker]
-
Please use @-tags for your code snippets or click on the code icon (the rightmost icon) in the editor. This way your code is formatted nicely and your chances that anyone takes care of what your write are much higher.
I've added them for you a last time.
Thanks.
-
I have to wonder: what do you hope to achieve by adding together values from two binary files who's formats you don't know? Who or what is supposed to use and make sense of the resulting file afterwards? And are you sure you want to just add two chars? How do you deal with overflows?
It just looks generally weird to me.
-
I am basically extracting the difference between a original image and the the image I could save to the disk. So, the difference when added to the original should give the file without any difference.
[quote author="Andre" date="1336045803"]I have to wonder: what do you hope to achieve by adding together values from two binary files who's formats you don't know? Who or what is supposed to use and make sense of the resulting file afterwards? And are you sure you want to just add two chars? How do you deal with overflows?It just looks generally weird to me. [/quote]
-
So... you're trying to create some kind of patch file for a binary file?
-
Yes in a way. A patch with difference is created and added to the original to remove the disparity in output image.
[quote author="Andre" date="1336048685"]So... you're trying to create some kind of patch file for a binary file?[/quote] -
What's the use of doing that? Note that your way of patching will only work if both files have the same size, and will produce files that have the same size as the original. I really fail to see the point of this excersise.
-
They'll be all the time.To keep it simple, it may be said that an encryption is patched to make it lossless.
[quote author="Andre" date="1336050201"]What's the use of doing that? Note that your way of patching will only work if both files have the same size, and will produce files that have the same size as the original. I really fail to see the point of this excersise.[/quote] -
You really lost me. If you want file encryption, I think there are better ways. Good luck with your project though!