inputBuffer: receiveType "Answer an input buffer for the receive type (String or ByteArray). Put the buffer in fixed space." "Buffers are freed by #freeInputBuffer: and are cleared it that time." ^[ | buffer pool bufferSize | StringInputBuffers isNil ifTrue: [StringInputBuffers := OrderedCollection new: 100]. ByteArrayInputBuffers isNil ifTrue: [ByteArrayInputBuffers := OrderedCollection new: 100]. bufferSize := 32768. "32 * 1024" pool := (receiveType == String) ifTrue: [StringInputBuffers] ifFalse: [ByteArrayInputBuffers]. buffer := pool notEmpty ifTrue: [pool removeLast] ifFalse: [receiveType new: bufferSize]. buffer makeFixed. ] critical.
freeInputBuffer: buffer "Clear and then put the input buffer for the receive type (String or ByteArray) into a pool for reuse." [ buffer isString ifTrue: [ buffer replaceFrom: 1 to: buffer size withObject: Nul. StringInputBuffers add: buffer. ] ifFalse: [ buffer replaceFrom: 1 to: buffer size withObject: 0. ByteArrayInputBuffers add: buffer. ]. ] critical.