Adding QByteArray
-
Yes, but its not working.
[quote author="1+1=2" date="1335892778"][quote author="christopher09" date="1335892180"]I am sorry . . It should be QByteArray. I want add the content of two binary files which are generated from a file. The overlap makes the output better outcome apropos the original.[/quote]So, you mean?
@
QByteArray z;
for(int k=0;k<qMin(x.size(), y.size());k++){
z.append(x[k]+y[k]);
}
@[/quote] -
[quote author="christopher09" date="1335905550"]Yes, but its not working.
[/quote]
So, how do you come to this conclusion? -
Unhandled exception at 0x75eb9673 in app.exe= Microsoft C++ exception: std::bad_alloc at memory location 0x001dc99c..
[quote author="1+1=2" date="1335906112"]
[quote author="christopher09" date="1335905550"]Yes, but its not working.
[/quote]
So, how do you come to this conclusion?[/quote] -
[quote author="christopher09" date="1335912902"]Unhandled exception at 0x75eb9673 in app.exe= Microsoft C++ exception: std::bad_alloc at memory location 0x001dc99c..
[/quote]I don't think above code will cause such an exception. what you need is: debug your application.
In additon, you can play with examples like this:
@
#include <QtCore>int main()
{
QByteArray x("\x01\x02\x03\x04"), y("\x05\x06\x07");QByteArray z; for(int k=0;k<qMin(x.size(), y.size());k++){ z.append(x[k]+y[k]); } qDebug()<<z.toHex(); return 0;
}
@ -
On compiling, Unhandled exception at 0x00c90364 in app.exe: 0xC0000005: Access violation reading location 0x00141934.
[quote author="1+1=2" date="1335913456"]
[quote author="christopher09" date="1335912902"]Unhandled exception at 0x75eb9673 in app.exe= Microsoft C++ exception: std::bad_alloc at memory location 0x001dc99c..
[/quote]I don't think above code will cause such an exception. what you need is: debug your application.
In additon, you can play with examples like this:
@
#include <QtCore>int main()
{
QByteArray x("\x01\x02\x03\x04"), y("\x05\x06\x07");QByteArray z; for(int k=0;k<qMin(x.size(), y.size());k++){ z.append(x[k]+y[k]); } qDebug()<<z.toHex(); return 0;
}
@[/quote] -
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!