Calculate buffer size once