please do not allocate on the stack - use SG_MALLOC here or some buffer