support arbitrary buffer size