private int allocate ( int size ) { while ( true ) { int prev = allocatePosition . get ( ) ; int next = prev + size ; if ( next >= buffer . capacity ( ) ) return - 1 ; if ( allocatePosition . compareAndSet ( prev , next ) ) return prev ; } }
allocate bytes in the segment or return - 1 if not enough space