[ruby-dev:49799] [Ruby trunk Bug#12754] Want to use prepared buffer with `Array#pack`
From:
nobu@...
Date:
2016-09-13 12:46:52 UTC
List:
ruby-dev #49799
Issue #12754 has been updated by Nobuyoshi Nakada. `Array#pack` provides `@` for `offset`. ---------------------------------------- Bug #12754: Want to use prepared buffer with `Array#pack` https://bugs.ruby-lang.org/issues/12754#change-60493 * Author: Usaku NAKAMURA * Status: Open * Priority: Normal * Assignee: * ruby -v: * Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN ---------------------------------------- `Array#pack` always returns new allocated `String`, but sometimes users want to use prepared buffer, especially the packed size is too large. I often uses `Fiddle` to call OS APIs, and encounter this problem as every time. I recommend to add keyword arguments for the purpose. ```ruby buf = '\0'*(32 * 1024 * 1024) # ... ary.pack(LONG_FORMAT, buffer: buf, offset: 4 * 1024) # returns `buf` ``` -- https://bugs.ruby-lang.org/