anchor.diff:        erlang:error(Error)
     end.
   
  -read_internal(Mem, Head) ->
  +read_first(Mem, Head) ->
     % Read the size of the next message
     {ok,   <<Sz:32/integer>>} = emmap:pread(Mem, Head, 4),
     BinSz  = Sz-8,  % The size read is inclusive of the 2 sizes written before/after the msg
     {ok,   <<Bin:BinSz/binary, EndSz:32/integer>>} = emmap:pread(Mem, Head+4, BinSz+4),
     EndSz /= Sz   andalso erlang:error({message_size_mismatch, {Sz, EndSz}, Head}),
     {binary_to_term(Bin), Head+Sz}.
  -
  + 
   update_head(Mem, NextHead) ->
     ok = emmap:pwrite(Mem, 4, <<NextHead:32/integer>>).
   
  
positive.code:   ?assertEqual(6, length(Mem)),
  
    % Dequeue data
    ?assertMatch({a, false}, pop_internal(Mem, true)),
    ?assertEqual(b,          pop(Mem)),
    ?assertEqual(c,          pop(Mem)),
    ?assertEqual(1,          pop(Mem)),
    ?assertMatch(2,          peek(Mem)),
    ?assertMatch(2,          try_pop(Mem, fun(2) -> 2 end)),
    ?assertError(failed,     try_pop(Mem, fun(3) -> erlang:error(failed) end)),
    ?assertMatch({3, true},  pop_internal(Mem, true)),
    ?assertEqual(nil,        pop(Mem)),
    ?assertEqual({112,112,112,1024}, header(Mem)),
    ?assert(purge(Mem)),
  
negative.code:   {Head, Tail, _, _} = header(Mem),
    F(Head, Tail, Init).
  
  read_head(Mem, Pop) ->
    case header(Mem) of
      {Head,  Tail, NextTail, _SegmSize} when Head < Tail, Head >= ?HEADER_SZ, Tail >= ?HEADER_SZ ->
        {Msg, NextHead} = read_first(Mem, Head),
        IsEnd  = (NextHead =:= Tail) andalso (NextHead =:= NextTail),
        case Pop of
          true ->
  