August 15, 2002
"Pavel Minayev" <evilone@omen.ru> wrote in message news:CFN374834661828819@news.digitalmars.com...
> So, what about using delete[] to remove items from array?

I don't have a good answer <g>.


August 15, 2002
Pavel Minayev <evilone@omen.ru> wrote in news:CFN374801183164468@news.digitalmars.com:

> On Sun, 11 Aug 2002 11:24:40 -0700 "Walter" <walter@digitalmars.com> wrote:
> 
>> It doesn't have to be. Better compilers can be tuned to recognize common idioms.
> 
> Well, for now we only have DMD fully working... does it able to optimize this case? If not, will it be able to do so in near future?..
> 
> Deleting an element is a basic operation, and it might be better to provide a distict method for it. Since you already use delete[] for associative arrays, then it could be used here as well:
> 
>      delete a[123];     // delete element #123

I like this.  Isn't it also consistant with the delete syntax for associative arrays?

August 21, 2002
"Patrick Down" <pat@codemoon.com> wrote in message news:Xns926B918ECEE58patcodemooncom@63.105.9.61...
> Pavel Minayev <evilone@omen.ru> wrote in news:CFN374801183164468@news.digitalmars.com:
>
> > On Sun, 11 Aug 2002 11:24:40 -0700 "Walter" <walter@digitalmars.com> wrote:
> >
> >> It doesn't have to be. Better compilers can be tuned to recognize common idioms.
> >
> > Well, for now we only have DMD fully working... does it able to optimize this case? If not, will it be able to do so in near future?..
> >
> > Deleting an element is a basic operation, and it might be better to provide a distict method for it. Since you already use delete[] for associative arrays, then it could be used here as well:
> >
> >      delete a[123];     // delete element #123
>
> I like this.  Isn't it also consistant with the delete syntax for associative arrays?

Consider the C++ code

int **a = new int *[200];
a[123] = new int;
delete a[123];

In C++ this deletes the memory allocated with the second "new", and leaves the array size 200. It would be clearer for C++ coders to use some other syntax in D for a completely different task. For example,

int []a;
a.length = 200;
a.erase(123);

The same goes for associative arrays.
Also I would be happy to see a syntax to write the first two lines of this
last example in one single line.

Sandor


August 21, 2002
On Wed, 21 Aug 2002 11:41:51 +0200 "Sandor Hojtsy" <hojtsy@index.hu> wrote:

> 
> Consider the C++ code
> 
> int **a = new int *[200];
> a[123] = new int;
> delete a[123];
> 
> In C++ this deletes the memory allocated with the second "new", and leaves the array size 200. It would be clearer for C++ coders to use some other syntax in D for a completely different task. For example,
> 
> int []a;
> a.length = 200;
> a.erase(123);
> 
> The same goes for associative arrays.

That syntax for D associative arrays exists for a long time already, I don't think it would be wise to change it now... on the other hand, applying it to simple arrays seems logical.

The simplest way to ensure correct behaviour is to use brackets:

	delete(a[123]);	// delete block pointer by a[123]

	delete(a)[123];	// delete element #123

August 21, 2002
Sandor Hojtsy wrote:
> "Patrick Down" <pat@codemoon.com> wrote in message
> news:Xns926B918ECEE58patcodemooncom@63.105.9.61...
> 
>>Pavel Minayev <evilone@omen.ru> wrote in
>>news:CFN374801183164468@news.digitalmars.com:
>>
>>
>>>On Sun, 11 Aug 2002 11:24:40 -0700 "Walter" <walter@digitalmars.com>
>>>wrote:
>>>
>>>
>>>>It doesn't have to be. Better compilers can be tuned to recognize
>>>>common idioms.
>>>
>>>Well, for now we only have DMD fully working... does it able to
>>>optimize this case? If not, will it be able to do so in near future?..
>>>
>>>Deleting an element is a basic operation, and it might be better to
>>>provide a distict method for it. Since you already use delete[] for
>>>associative arrays, then it could be used here as well:
>>>
>>>     delete a[123];     // delete element #123
>>
>>I like this.  Isn't it also consistant with the delete syntax
>>for associative arrays?
> 
> 
> Consider the C++ code
> 
> int **a = new int *[200];
> a[123] = new int;
> delete a[123];
> 
> In C++ this deletes the memory allocated with the second "new", and leaves
> the array size 200. It would be clearer for C++ coders to use some other
> syntax in D for a completely different task. For example,

How about "remove" instead of "delete"?

August 21, 2002
On Wed, 21 Aug 2002 11:56:26 -0700 Russell Lewis <spamhole-2001-07-16@deming-os.org> wrote:

> How about "remove" instead of "delete"?

I don't mind. Not sure if Walter doesn't, though. =)
August 21, 2002
Hi,

"Russell Lewis" <spamhole-2001-07-16@deming-os.org> wrote in message news:3D63E25A.3020108@deming-os.org...
> How about "remove" instead of "delete"?

One of the strengths of D, is its ability to use the C libraries directly. It wouldn't be wise to have a keyword that is also a function in the C standard libraries, because it would prevent you from calling it.

Regards,
Martin M. Pedersen



1 2 3
Next ›   Last »