Any way to set len and ptr in dyn arrays?

James Dunne james.jdunne at
Tue Aug 8 15:54:28 PDT 2006

nobody wrote:
> James Dunne wrote:
>> This is very interesting and all, but why would you do such a thing?
>> Is the .length property on the dynamic array just not cuttin' it for you?
> No it is not. The whole raison d'etre for that array is to give me 
> access to the data in buf. From my reading of the docs it looks like any 
> case in which the length increases then this array can be copied and 
> might not point to the data in buf anymore. So now if I tried to save 
> changes to buf by passing it to the std.file.write method it would look 
> like nothing happened.

I'm still not following you.

You want to access, on the byte level, the compiler-dependent 
implementation details of how dynamic arrays work.  I get that.  But why?


// Sample program (with v0.163):
import	std.file;

int main(char[][] args) {
	char[]	myFileContents = cast(char[])"hello.txt");

	size_t	origLength = myFileContents.length;
	myFileContents.length = origLength + 20;
	myFileContents[origLength .. $] = "20 characters here!!";

	std.file.write("hello2.txt", cast(void[]) myFileContents);

	return 0;

Show me pseudo code of the larger problem you're trying to solve.  I 
think your assumptions on the way D's dynamic arrays work are getting in 
the way here.

Version: 3.1
GCS/MU/S d-pu s:+ a-->? C++++$ UL+++ P--- L+++ !E W-- N++ o? K? w--- O 
M--@ V? PS PE Y+ PGP- t+ 5 X+ !R tv-->!tv b- DI++(+) D++ G e++>e 
h>--->++ r+++ y+++

James Dunne

More information about the Digitalmars-d-learn mailing list