[erlang-questions] Binary pattern matching and optimization

Vance Shipley vances@REDACTED
Mon Nov 24 20:27:30 CET 2008


Robert,

My thinking was that reading a big binary and then passing it 
with offsets to various parsing functions would be easier on
the emulator than creating a new binary for each one.  Is it
the case that the compiler will optimize away the creation of
these binaries?

	-Vance

On Mon, Nov 24, 2008 at 08:10:38PM +0100, Robert Virding wrote:
}  The compiler and VM is smart and optimises the matching of a binary where
}  the last segment is a binary. This makes it more efficient to use a binary
}  like a list and pick things off the front.
}  
}  *BUT* for this to work the reference to the whole binary, Bin your case,
}  must not be used after the match, then the compiler can reuse that binary
}  reference and save work. You reuse Bin and the compiler is warning you that
}  when you do this it can't do a good a job as possible.



More information about the erlang-questions mailing list