If you want to save a dynamic array to the disk using BlockWrite you have two ways to write things correctly:
1) BlockWrite(fOut, Pointer(myArray)^, NumberOfBytes); or 2a) BlockWrite(fOut, myArray[0], NumberOfBytes); You may use the following form Instead of indexing with 0: 2b) BlockWrite(fOut, myArray[Low(myArray)], NumberOfBytes); The explanation is that when you have an untyped parameter, you must precede the parameter name with either *var* or *const*. In both cases, the parameter you pass uses the *pass by reference* rule. myArray is actually a pointer. So when you pass it to the function just as myArray, the routine will consider that it has to work with the data that is stored at the address where myArray is stored. That means you are trying to read/write only on the 4 bytes of myArray pointer. This also applies to strings and PChars. --- On Thu, 3/26/09, hjansenvanrensburg <[email protected]> wrote: From: hjansenvanrensburg <[email protected]> Subject: [delphi-en] Re: dumping dynamic array to a file To: [email protected] Date: Thursday, March 26, 2009, 9:00 AM I don't have definitive answers to your questions, but I have some ideas: 1) The major difference between static arrays and dynamic arrays is that static arrays are normal variables, whereas dynamic arrays are pointers. I guess what might be happening is that when you pass your dynamic array to the BlockWrite procedure as an untyped var, it is the memory data for the POINTER (and the stuff from there onwards) that is being written to the disk. You want to write the stuff that the pointer is pointing to be written to disk, so you have to dereference that pointer somehow and pass that data to the BlockWrite procedure. 2) I have a suspicion that the optimal buffer to write to disk depends on many factors. Common sense tends to tell me that a buffer size similar to the hard disk's sector size would be faster to write than arbitrary sizes. Is this true though, given hard disk caching, etc? I don't know. Ultimately, will the gain in speed from writing in optimally sized chunks be noticeable to the user? I don't know. I suggest you play around and perhaps you can let us know what you find? [Non-text portions of this message have been removed]

