Pointer to array allocation

BCS ao at pathlink.com
Mon Jun 18 12:16:38 PDT 2007


Reply to Myron,

> 0ffh wrote:
> 
>> @Myron: Thanks, too!
>> 
> No problem.
> 
> I'm curious as to the reason for a pointer to a dynamic array instead
> of a pointer to the array? How do you use the Lst* and what does it
> allow you to do that the pointer to the array cannot.
> 
> Regards,
> 
> Myron.
> 

I have done this befor

typedef char[] char_str
typedef char_str* char_str_ptr


char_str[] data;  //set up data holes
data.length = 3;

    //set up template
char_str[] template = ["hello "[], "\n you have won a ", " and it will be 
sent to ", \n];

    // build array of parts
char_str_ptr[] all = [&template[0], &data[0], &template[1], &data[1], &template[2], 
&data[2], &template[3]];

   // fill holes
data[0] = "bob";
data[1] = "fork";
data[3] = "123 2nd st";

  // dump
foreach(i, all) writef("%s", *i);

   // refill holes
data[0] = "sally";
data[1] = "airplane";
data[3] = "1645 w apple Avn.";

  //dump again
foreach(i, all) writef("%s", *i);




More information about the Digitalmars-d-learn mailing list