Hello David,

> for the "ptrTemp".  (1) What is the best number , i.e. a number
> that gaurentee  it is not to o small, while not occupying too much 
> memory?

8 KB is a good size if you have a fast network.

> have ptrTemp as a fixed size buffer  determined at design time, and have
> it locally in OnDataAvailable?

Yes. Then it occupies no memory, take no time to (de)initialize. It is
just on the stack.

---
Rgds, Wilfried [TeamICS]
http://www.overbyte.be/eng/overbyte/teamics.html
http://www.mestdagh.biz

Tuesday, November 1, 2005, 20:57, Kei wrote:

> I got it. so this is what I'll do:

A>> txt 10240
B>> (malloc ptrAltogether 10240 bytes; Let sizeRemain = 10240;sizeDone=0)
>    sendtxt
A>> "010010101010101......."
B>> (First packet is ready:
>     var ptrTemp: array[0..MAX_PACK] of char;
>     Zero(ptrTemp);
>     if(sizeThisPack = Receive(ptrTemp) > 0)
>     {
>       sizeRemain -= sizeThispack;
>       sizeone += sizeThisPack;
>            copy memory( from ptrTemp to "ptrReceive+sizeDone", 
> size=sizeThisPack);
>        }
A>> ".......01010101"
 B>> (Last packet is ready
>        (Do all t he memory copying as above...
>         this time, add the followings:
>        generate hash, verify
>     call a "Callback function" to notify the user, while passing the 
> pointer to him

> So my question is..
> first, for the "ptrTemp".  (1) What is the best number , i.e. a number
> that gaurentee  it is not to o small, while not occupying too much 
> memory? (2) Second, is it better to have ptrTemp as a local variable 
> inside OnDataAvailable()? OR is it better to have it as a global 
> variable? Third, is it etter to :

> have ptrTemp as a pointer only,
> GetMem for "ptrTemp" right  at  the beginning, then
> Free it at the very last?
   
> or

> have ptrTemp as a fixed size buffer  determined at design time, and have
> it locally in OnDataAvailable?

> Thanks!

> Wilfried Mestdagh wrote:

>>Hello David,
>>
>>  
>>
>>>So I ignored the zero und -1 returned by the Receive(), and it worked :)
>>>    
>>>
>>
>>Great !  I'm glad it works for you :)
>>
>>  
>>
>>>But the "TempSize" in my code was never changed. it was set as to a 
>>>constant value en the constructor.
>>>    
>>>
>>
>>Ok no problem then. But if your buffer has a constant size, then wy not
>>put it on the stack like this:
>>var
>>  Buffer: array[0..TempSize] of char;
>>begin
>>  // receive in buffer
>>
>>  
>>
>>>decrease the GetMem(), Free() as much as possible.. so I think I'll do
>>>it before the first request, and free it after the last request...
>>>    
>>>
>>
>>Yes that's another option. Then you only have 1 time allocation, but see
>>paragraph above.
>>
>>  
>>
>>>for reassembling the original stream, what do you think ? "consecutive
>>>Realloc()" (First scenario) or "Array of pointer" (Second scenario)?
>>>    
>>>
>>
>>Difficult to say wahts best because it is depending on what you exacly
>>wants or have to do with it.
>>
>>- if you have to save it to a file then you can:
>>  - open the file at first packet
>>  - receive in buffer
>>  - write buffer direkt to file
>>  - close file at last packet
>>  -- the most fast is to use the low level routines: FileOpen(), etc...
>>
>>- TFileStream is another option, somewhat slower
>>
>>- if you have to do other things with it then you can
>>  - use a TMemoryStream
>>  - or a dynamicly allocate buffer that you take care yurself
>>
>>  Both of course will reallocate when data grow, however you can for
>>  both options set the size at first, then also only 1 memallcoation and
>>  no reallocation.
>>
>>- array of pointer seems more difficult. Dont think you will have
>>  advantage using it.
>>
>>---
>>Rgds, Wilfried [TeamICS]
>>http://www.overbyte.be/eng/overbyte/teamics.html
>>http://www.mestdagh.biz
>>
>>  
>>


-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Reply via email to