Added the capability of allocating mem dynamically

Allocated memory at the beginning for incoming messages. But if the
preallocate memory is used up, then allocate more memory dynamically.

Signed-off-by: Huy Bui <huybui@anl.gov>