Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use GetMem/FreeMem with a generic buffer instead of using a dynamic array. It is much more alike the way you would do it in C.</p> <p>Anyway setting a buffer as large as the file is not usually the best solution. Usually you use a fixed size buffer and read/write a file in chunks. You may not be able to allocate a whole array, even if there is enough free memory. Array memory needs to be contiguous, thereby you need a free memory block as large as or larger than the array you need to allocate. Memory can get fragmented over time, so a block large enough could not be available.</p> <p>And even if you're able to allocate it, you may force the OS to swap some memory out of RAM to allocate it - slowing down other applications. The size of the buffer should thereby be set taking into account available RAM, performance, and disks speed.</p> <p>How Delphi allocates memory depends on what memory manager you're using. Most will request larger blocks using Windows memory allocation functions, and suballocate them as needed (to speed up memory management, Windows was not designed to allocate efficiently small memory blocks as most OO applications do). Blocks can be returned to the OS only when they contains no longer used data.</p> <p>Why an array of <strong>char</strong>? In Delphi a char is not an 8 bit type. For example it is 8 bit up to Delphi 2007, but a 16 bit type from 2009 onwards, because it became a Unicode char (unlike C). Use the Byte type (or UInt8 in newer versions), it will stay an 8 bit type whatever version of Delphi and target platform you use.</p> <p>If you need to copy a file, TStream.CopyFrom() will do what you need in a single call (after you've created both streams).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload