Click here to Skip to main content
15,905,028 members
Home / Discussions / C#
   

C#

 
AnswerRe: Properties and User Ma... Pin
Dave Kreskowiak29-Nov-08 4:59
mveDave Kreskowiak29-Nov-08 4:59 
GeneralRe: Properties and User Ma... Pin
jas0n2329-Nov-08 5:14
jas0n2329-Nov-08 5:14 
Question[Message Deleted] Pin
jas0n2328-Nov-08 19:33
jas0n2328-Nov-08 19:33 
AnswerRe: URL Regular Expression f... Pin
AhsanS28-Nov-08 20:36
AhsanS28-Nov-08 20:36 
GeneralRe: URL Regular Expression f... Pin
jas0n2328-Nov-08 20:40
jas0n2328-Nov-08 20:40 
AnswerRe: URL Regular Expression f... Pin
Guffa28-Nov-08 20:36
Guffa28-Nov-08 20:36 
AnswerRe: URL Regular Expression f... Pin
Garth J Lancaster28-Nov-08 23:49
professionalGarth J Lancaster28-Nov-08 23:49 
QuestionConverting byte[] to a stream Pin
darkzangel28-Nov-08 18:17
darkzangel28-Nov-08 18:17 
I'm currently working on a c# project that need winsock in it. WebClient wasn't enought powerfull for my kind of application. So, I writed from scratch all the code to get all thing in my project with a custom webclient. Everything work fine, but I want to improve my code. One of my problem is a function that read byte from the recv function (recv is a c++ winsock function) and then send it to a stream to eventually get an array of byte (byte[]). If you take a closer look to my code, you will see that I copy twice the data. The first time, I make the convertion from byte* (IntPtr receiveBuff) to byte[] and then, I copy again those data to the stream with mem.Write(). I will like to only to it once. Doesn't any body know a better way to do this so I only have to make one copy of my data?

[DllImport("Ws2_32.dll")]
public static extern int recv(SOCKET s, byte* buf, int len, int flags);

public unsafe byte[] RecvAsBytes()
{
    MemoryStream mem = new MemoryStream();
    int receivedLen;
    IntPtr receiveBuff = Marshal.AllocHGlobal(1024);
    byte[] receiveBuff2 = new byte[1024];
    while ((receivedLen = recv(socket, (byte*)receiveBuff, 1024, 0)) != 0)
    {
        Marshal.Copy(receiveBuff, receiveBuff2, 0, receivedLen);
        mem.Write(receiveBuff2, 0, receivedLen);
    }
    Marshal.FreeHGlobal(receiveBuff);
    return mem.ToArray();
}

GeneralRe: Converting byte[] to a stream Pin
Luc Pattyn28-Nov-08 18:32
sitebuilderLuc Pattyn28-Nov-08 18:32 
GeneralRe: Converting byte[] to a stream Pin
darkzangel29-Nov-08 9:32
darkzangel29-Nov-08 9:32 
GeneralRe: Converting byte[] to a stream Pin
Luc Pattyn29-Nov-08 10:35
sitebuilderLuc Pattyn29-Nov-08 10:35 
Questiontime-division multiplexing Pin
Member 391904928-Nov-08 7:26
Member 391904928-Nov-08 7:26 
AnswerRe: time-division multiplexing Pin
User 665828-Nov-08 11:05
User 665828-Nov-08 11:05 
AnswerRe: time-division multiplexing Pin
Guffa28-Nov-08 11:10
Guffa28-Nov-08 11:10 
AnswerRe: time-division multiplexing Pin
Nicholas Butler28-Nov-08 13:22
sitebuilderNicholas Butler28-Nov-08 13:22 
GeneralRe: time-division multiplexing Pin
Dave Kreskowiak28-Nov-08 15:36
mveDave Kreskowiak28-Nov-08 15:36 
GeneralRe: time-division multiplexing Pin
PIEBALDconsult28-Nov-08 16:11
mvePIEBALDconsult28-Nov-08 16:11 
QuestionCan different processes share memory? Pin
Member 391904928-Nov-08 7:25
Member 391904928-Nov-08 7:25 
AnswerRe: Can different processes share memory? PinPopular
J. Dunlap28-Nov-08 9:50
J. Dunlap28-Nov-08 9:50 
Questionc# source code and produces the source code in S-style(Banner Style) indentation Pin
sp198428-Nov-08 6:48
sp198428-Nov-08 6:48 
AnswerRe: c# source code and produces the source code in S-style(Banner Style) indentation Pin
EliottA28-Nov-08 6:57
EliottA28-Nov-08 6:57 
AnswerRe: c# source code and produces the source code in S-style(Banner Style) indentation Pin
Thomas Weller28-Nov-08 6:57
Thomas Weller28-Nov-08 6:57 
AnswerRe: c# source code and produces the source code in S-style(Banner Style) indentation Pin
Ashfield28-Nov-08 8:48
Ashfield28-Nov-08 8:48 
GeneralRe: c# source code and produces the source code in S-style(Banner Style) indentation Pin
Wendelius28-Nov-08 8:59
mentorWendelius28-Nov-08 8:59 
AnswerRe: c# source code and produces the source code in S-style(Banner Style) indentation Pin
Christian Graus28-Nov-08 16:15
protectorChristian Graus28-Nov-08 16:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.