Answer the question
In order to leave comments, you need to log in
How to convert cli::array ^ to byte *??
Help me please. I've been scratching my head for two days now how to convert.
The essence of the program, as I understand it: you need to read a piece of a file, 65536 bytes in size.
And send it to the C memmove command. Which does a simple thing...move bytes.
And everything would be fine, but I am writing a program in visual c ++ 2013 in which there are wonderful tools like cli. Stubbornly there is a type mismatch error...here is the code:
This sets the variables and starts reading the file. The file is read correctly and well, but it is read into an array, but not into an array ... look at the following code ... it's clear where to go.
FileStream^ fs;
try
{
fs = File::OpenRead(File);
}
catch (Exception^ ex)
.....
const int BUFFER_SIZE = 65536;
char *szBuffer = new char[BUFFER_SIZE];
unsigned char buf[BUFFER_SIZE];
array<unsigned char>^ b = gcnew array<unsigned char>(BUFFER_SIZE);
UTF8Encoding^ temp = gcnew UTF8Encoding(true);
__int64 iPrevReaded = 0;
__int64 Start = TimerInit();
String^ g;
int cbReaded = 0;
// чтение из файла и вычисление TTH
while ((cbReaded = fs->Read(b, 0, BUFFER_SIZE)) > 0)
{
g=temp->GetString(b);
//cli::pin_ptr<System::Byte> p = g;
tt_update(&ctx, b, cbReaded);
void tt_update(TT_CONTEXT *ctx, byte *buffer, word32 len)
{
if (ctx->index)
{ /* Try to fill partial block */
unsigned left = BLOCKSIZE - ctx->index;
if (len < left)
{
memmove(ctx->block + ctx->index, buffer, len);
ctx->index += len;
Answer the question
In order to leave comments, you need to log in
Use pin_ptr
array<Byte>^ bytes = File::ReadAllBytes( fileName );
pin_ptr<unsigned char> pptr = &bytes[0];
const int BUFFER_SIZE = 65536;
unsigned char buf [ BUFFER_SIZE ];
memcpy_s( buf, sizeof(buf), pptr, bytes->Length );
If you've messed up C++, use std::move.
You're trying to shoot yourself in the foot.
When the garbage collector is actively used in one code, and they try to stick a low-level function from C, because they heard somewhere that it is fast, while the size is kept in an integer variable, I feel sad.
The proper textbook for writing TCP/IP applications is called "Using TCP/IP Effectively" by J. Sneijder.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question