tempAlloc

Creates temporary buffer.

Returned object has two properties: ptr to access the buffer as T* and arr to access it as T[].

The temporary buffer is valid unless returned object is destroyed. Thus if returned object is assigned to a variable the temporary is valid unless the variable goes out of scope. If returned object isn't assigned to a variable it will be destroyed at the end of creating primary expression.

If count <= stackCount or stackCount isn't specified and no more than 1 KiB is requested tempAlloc will use stack allocated buffer, for larger requests it will allocate temporary buffer from threadHeap.

Preconditions: count != 0

Note: This function can be used in function call expression (like needBuffFunc(tempAlloc(n).ptr)). Incorrect usage of this function may lead to memory corruption. See WARNING in tempCString Examples section (tempCString is an analog of tempAlloc for C strings).

  1. auto tempAlloc(size_t count, bool initialize)
    @system
    tempAlloc
    (
    T
    )
    (
    in size_t count
    ,
    in bool initialize = true
    )
  2. auto tempAlloc(size_t count, bool initialize)
  3. auto tempAlloc(size_t count, bool initialize)

See Also

$(DPREF2 c, string, tempCString)

Meta