Home » Developing U++ » U++ Developers corner » Core chat... (reference counted pointers etc.)
Re: Core chat... [message #12321 is a reply to message #12318] |
Wed, 24 October 2007 20:24   |
mdelfede
Messages: 1308 Registered: September 2007
|
Ultimate Contributor |
|
|
luzr wrote on Wed, 24 October 2007 18:23 |
Well, I guess there is always instrinsict conflict between performance, convenience and safety.
|
Speaking about performance, I agree... it shouldn't traded with convenience. With safety.... hmmm... there I have some reserve.
But, in modern compilers, doing a 3 line construct or an equivalent 1 liner At() should be the same in terms of performance.
BTW, I really see few practical usage of At(); normally (about 100% of cases) you know in advance your needed array size, and, if you don't, I don't really see the point of increasing (and such copying the whole stuff) the array on a 1 element basis; se that example :
Array<int> a(1);
for(int i = 2, i < 1000; i++)
a.At(i) = i;
of course that works, but that means, in the worst case of a badly written Array code, 998 realloc() calls, with 998 buffer copy, memory releases and allocations, ecc ecc.
In a better and more realistic case, if the array is grown in chunks of 10 elements, you'd still have to do it 98 times. That's no efficiency neither good code.
Of course there's a better solution (here I added 1 member functions to Array class) :
Array<int> a(1);
for(int i = 2, i < 1000; i++)
{
a.CheckSize(i, 1000);
a[i] = i;
}
Where the CheckSize(minSize, increment) is a member function that checks the actual/required size of array and, if too small, make it to grow of a specified size (here 1000).
That'd be an huge preformance gain with a small line of code added.
Quote: |
"At", and in fact, the whole concept of "inplace creation" (instances get created in container, reference is returned) is nothing new, it is part of U++ design since the very beginning and proved to be very useful.
In any case, I believe I would make more bugs in "unrolling"
a.At(x).At(y) = ...
code than using such utility method.
|
Here I'd let the At() the sole purpose of element accessor and put somewhere else the array resize. I don't see nothing bad on a.At().At().At(), as they don't change array sizes.
Ciao
Max
|
|
|
 |
|
Core chat... (reference counted pointers etc.)
By: mirek on Tue, 23 October 2007 23:48
|
 |
|
Re: Core chat...
|
 |
|
Re: Core chat...
By: mirek on Wed, 24 October 2007 16:37
|
 |
|
Re: Core chat...
|
 |
|
Re: Core chat...
By: mdelfede on Wed, 24 October 2007 17:46
|
 |
|
Re: Core chat...
By: mirek on Wed, 24 October 2007 18:23
|
 |
|
Re: Core chat...
By: mdelfede on Wed, 24 October 2007 20:24
|
 |
|
Re: Core chat...
By: mirek on Wed, 24 October 2007 22:05
|
 |
|
Re: Core chat...
By: mdelfede on Wed, 24 October 2007 23:36
|
 |
|
Re: Core chat...
By: mirek on Thu, 25 October 2007 05:33
|
 |
|
Re: Core chat...
By: mdelfede on Thu, 25 October 2007 14:06
|
 |
|
Re: Core chat...
By: mirek on Thu, 25 October 2007 14:34
|
 |
|
Re: Core chat...
By: mdelfede on Thu, 25 October 2007 15:19
|
 |
|
Re: Core chat...
By: mirek on Thu, 25 October 2007 18:02
|
 |
|
Re: Core chat...
By: mdelfede on Thu, 25 October 2007 19:52
|
 |
|
Re: Core chat...
By: mirek on Thu, 25 October 2007 21:33
|
 |
|
Re: Core chat...
By: mdelfede on Thu, 25 October 2007 23:26
|
 |
|
Re: Core chat...
By: mirek on Thu, 25 October 2007 23:38
|
 |
|
Re: Core chat...
By: mdelfede on Thu, 25 October 2007 23:47
|
 |
|
Re: Core chat...
By: mirek on Fri, 26 October 2007 09:36
|
 |
|
Re: Core chat...
By: mdelfede on Fri, 26 October 2007 12:13
|
 |
|
Re: Core chat...
By: mirek on Fri, 26 October 2007 12:42
|
 |
|
Re: Core chat...
By: mdelfede on Fri, 26 October 2007 13:03
|
 |
|
Re: Core chat...
By: mirek on Fri, 26 October 2007 14:01
|
 |
|
Re: Core chat...
By: mdelfede on Fri, 26 October 2007 14:18
|
 |
|
Re: Core chat...
By: mirek on Fri, 26 October 2007 22:09
|
 |
|
Re: Core chat...
By: mdelfede on Fri, 26 October 2007 23:13
|
 |
|
Re: Core chat...
By: mirek on Fri, 26 October 2007 23:51
|
 |
|
Re: Core chat...
By: mdelfede on Fri, 26 October 2007 18:47
|
 |
|
Re: Core chat...
By: mirek on Fri, 26 October 2007 22:12
|
 |
|
Re: Core chat...
By: mdelfede on Fri, 26 October 2007 23:09
|
 |
|
Re: Core chat...
By: mirek on Fri, 26 October 2007 23:55
|
 |
|
Re: Core chat...
By: mdelfede on Sat, 27 October 2007 11:08
|
 |
|
Re: Core chat...
By: mirek on Sat, 27 October 2007 11:16
|
 |
|
Re: Core chat...
By: mdelfede on Sat, 27 October 2007 13:06
|
 |
|
Re: Core chat...
By: mirek on Sat, 27 October 2007 14:50
|
 |
|
Re: Core chat...
By: mdelfede on Sat, 27 October 2007 15:21
|
 |
|
Re: Core chat...
By: mirek on Sat, 27 October 2007 16:02
|
 |
|
Re: Core chat...
By: mdelfede on Sat, 27 October 2007 16:28
|
 |
|
Re: Core chat...
By: sergei on Wed, 24 October 2007 19:49
|
 |
|
Re: Core chat...
By: mdelfede on Wed, 24 October 2007 20:06
|
 |
|
Re: Core chat...
By: mirek on Wed, 24 October 2007 21:46
|
Goto Forum:
Current Time: Sat May 10 10:10:38 CEST 2025
Total time taken to generate the page: 0.03004 seconds
|