copy method

PWSTR copy({
  1. Allocator allocator = adaptiveCalloc,
})

Creates a deep copy of this string into newly allocated native memory.

The returned pointer is owned by the caller.

  • If allocated with the default allocator, it must be released with free.
  • If an Arena or custom allocator is provided, the memory is released according to that allocator’s rules.

Implementation

PWSTR copy({Allocator allocator = adaptiveCalloc}) {
  final pwstr = allocator<WCHAR>(length + 1);
  pwstr
      .asTypedList(length + 1)
      .setAll(0, cast<WCHAR>().asTypedList(length + 1));
  return .new(pwstr.cast());
}