Ho un buffer di array di byte della dimensione massima 1K. Voglio scrivere un sottoinsieme dell'array (l'inizio del sottoinsieme sarà sempre l'elemento 0, ma la lunghezza a cui siamo interessati è in una variabile).Come posso ottenere in modo efficiente un sottoinsieme di un array di byte (primi N elementi) in C#?
L'applicazione qui è compressione. Passo in un buffer ad una funzione di compressione. Per semplicità, supponiamo che la compressione porterà a dati uguali o inferiori a 1K byte.
byte[] buffer = new byte[1024];
while (true)
{
uncompressedData = GetNextUncompressedBlock();
int compressedLength = compress(buffer, uncompressedData);
// Here, compressedBuffer[0..compressedLength - 1] is what we're interested in
// There's a method now with signature Write(byte[] compressedData) that
// I won't be able to change. Short of allocating a custom sized buffer,
// and copying data into the custom sized buffer... is there any other
// technique I could use to only expose the data I want?
}
mi piacerebbe davvero evitare una copia qui - mi sembra del tutto inutile, in quanto tutti i dati necessari è in buffer
già.
Wow, mi hai già aiutato con WCF (come utente diverso). Grazie ancora per la punta Carlos +1. – jglouie