Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #21381 > unrolled thread
| Started by | jacob navia <jacob@spamsink.net> |
|---|---|
| First post | 2012-05-27 00:22 +0200 |
| Last post | 2012-05-29 01:40 -0600 |
| Articles | 20 on this page of 50 — 14 participants |
Back to article view | Back to comp.lang.c
Open letter to Ian Collins jacob navia <jacob@spamsink.net> - 2012-05-27 00:22 +0200
Re: Open letter to Ian Collins Ike Naar <ike@sverige.freeshell.org> - 2012-05-26 22:36 +0000
Re: Open letter to Ian Collins jacob navia <jacob@spamsink.net> - 2012-05-27 01:13 +0200
Re: Open letter to Ian Collins Barry Schwarz <schwarzb@dqel.com> - 2012-05-26 16:53 -0700
Re: Open letter to Ian Collins Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-05-26 16:41 -0700
Re: Open letter to Ian Collins pete <pfiland@mindspring.com> - 2012-05-26 22:43 -0400
Re: Open letter to Ian Collins Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-05-26 15:41 -0700
Re: Open letter to Ian Collins jacob navia <jacob@spamsink.net> - 2012-05-27 01:14 +0200
Re: Open letter to Ian Collins MelissA <melis@a.com> - 2012-05-27 00:52 +0200
Re: Open letter to Ian Collins Stephen Sprunk <stephen@sprunk.org> - 2012-05-26 20:40 -0500
Re: Open letter to Ian Collins jacob navia <jacob@spamsink.net> - 2012-05-27 09:32 +0200
Re: Open letter to Ian Collins pete <pfiland@mindspring.com> - 2012-05-27 07:18 -0400
Re: Open letter to Ian Collins Ian Collins <ian-news@hotmail.com> - 2012-05-27 14:24 +1200
Re: Open letter to Ian Collins "BartC" <bc@freeuk.com> - 2012-05-27 10:36 +0100
Re: Open letter to Ian Collins Ian Collins <ian-news@hotmail.com> - 2012-05-27 22:33 +1200
Re: Open letter to Ian Collins "BartC" <bc@freeuk.com> - 2012-05-27 12:25 +0100
Re: Open letter to Ian Collins Ian Collins <ian-news@hotmail.com> - 2012-05-28 07:17 +1200
Re: Open letter to Ian Collins Ike Naar <ike@sverige.freeshell.org> - 2012-05-27 13:03 +0000
Re: Open letter to Ian Collins Ian Collins <ian-news@hotmail.com> - 2012-05-27 15:16 +1200
Re: Open letter to Ian Collins jacob navia <jacob@spamsink.net> - 2012-05-27 09:30 +0200
Re: Open letter to Ian Collins Ian Collins <ian-news@hotmail.com> - 2012-05-27 20:56 +1200
Re: Open letter to Ian Collins jacob navia <jacob@spamsink.net> - 2012-05-27 11:12 +0200
Re: Open letter to Ian Collins Ian Collins <ian-news@hotmail.com> - 2012-05-27 21:22 +1200
Re: Open letter to Ian Collins pete <pfiland@mindspring.com> - 2012-05-27 07:15 -0400
Re: Open letter to Ian Collins Keith Thompson <kst-u@mib.org> - 2012-05-27 07:49 -0700
Re: Open letter to Ian Collins pete <pfiland@mindspring.com> - 2012-05-27 13:55 -0400
Re: Open letter to Ian Collins jacob navia <jacob@spamsink.net> - 2012-05-27 22:24 +0200
Re: Open letter to Ian Collins "BartC" <bc@freeuk.com> - 2012-05-27 22:09 +0100
Re: Open letter to Ian Collins Keith Thompson <kst-u@mib.org> - 2012-05-27 14:33 -0700
Re: Open letter to Ian Collins pete <pfiland@mindspring.com> - 2012-05-27 17:49 -0400
Re: Open letter to Ian Collins pete <pfiland@mindspring.com> - 2012-05-27 17:31 -0400
Re: Open letter to Ian Collins Philip Lantz <prl@canterey.us> - 2012-05-28 01:38 -0700
Re: Open letter to Ian Collins pete <pfiland@mindspring.com> - 2012-05-28 08:18 -0400
Re: Open letter to Ian Collins "BartC" <bc@freeuk.com> - 2012-05-27 15:46 +0100
Open letter to Ian Collins pete <pfiland@mindspring.com> - 2012-06-13 21:25 -0400
Re: Open letter to Ian Collins pete <pfiland@mindspring.com> - 2012-06-13 21:52 -0400
Re: Open letter to Ian Collins jacob navia <jacob@spamsink.net> - 2012-06-14 04:00 +0200
Re: Open letter to Ian Collins pete <pfiland@mindspring.com> - 2012-06-14 00:04 -0400
Re: Open letter to Ian Collins jacob navia <jacob@spamsink.net> - 2012-05-27 09:42 +0200
Re: Open letter to Ian Collins "io_x" <a@b.c.invalid> - 2012-05-28 12:39 +0200
Re: Open letter to Ian Collins "io_x" <a@b.c.invalid> - 2012-05-28 21:44 +0200
Re: Open letter to Ian Collins jacob navia <jacob@spamsink.net> - 2012-05-29 09:46 +0200
Re: Open letter to Ian Collins "io_x" <a@b.c.invalid> - 2012-05-29 10:06 +0200
Re: Open letter to Ian Collins "io_x" <a@b.c.invalid> - 2012-05-29 10:37 +0200
Re: Open letter to Ian Collins "io_x" <a@b.c.invalid> - 2012-05-29 10:58 +0200
Re: Open letter to Ian Collins "Joachim Schmitz" <nospam.jojo@schmitz-digital.de> - 2012-05-29 11:34 +0200
Re: Open letter to Ian Collins Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-05-29 03:02 -0700
Re: Open letter to Ian Collins "io_x" <a@b.c.invalid> - 2012-05-29 09:59 +0200
Re: Open letter to Ian Collins "io_x" <a@b.c.invalid> - 2012-05-29 20:09 +0200
Re: Open letter to Ian Collins "Sarah Wren" <swreb@ameritech.net> - 2012-05-29 01:40 -0600
Page 1 of 3 [1] 2 3 Next page →
| From | jacob navia <jacob@spamsink.net> |
|---|---|
| Date | 2012-05-27 00:22 +0200 |
| Subject | Open letter to Ian Collins |
| Message-ID | <jprl29$ifd$1@speranza.aioe.org> |
Hi Ian
In the c++ newsgroup you asked me for an example of the ccl performance
It was something with building a huge list, then sorting it, if I
remember correctly...
I have built this example code:
#include <stdlib.h>
#include "containers.h"
#define N 10000000
int main(void)
{
List *L1;
size_t i,d;
long long sum=0,newSum=0;
Iterator *it;
int *pint;
L1 = iList.Create(sizeof(int));
iList.UseHeap(L1,NULL);
for (i=0; i<N;i++) {
d = rand();
sum += d;
iList.Add(L1,&d);
}
iList.Sort(L1);
it = iList.NewIterator(L1);
for (pint = it->GetFirst(it); pint; pint = it->GetNext(it)) {
newSum += *pint;
}
if (sum != newSum)
printf("Failed\n");
else printf("Sum = %lld\n",sum);
iList.Finalize(L1);
}
This creates a list, then fills it with 10 million random integers,
then sorts it and verifies that all the data is still there by
accessing all elements of the list with an iterator.
Can you please send me an equivalent C++program?
Thanks
[toc] | [next] | [standalone]
| From | Ike Naar <ike@sverige.freeshell.org> |
|---|---|
| Date | 2012-05-26 22:36 +0000 |
| Message-ID | <slrn3vfsjs2mnd.rrv.ike@sverige.freeshell.org> |
| In reply to | #21381 |
On 2012-05-26, jacob navia <jacob@spamsink.net> wrote:
> Hi Ian
>
> In the c++ newsgroup you asked me for an example of the ccl performance
> It was something with building a huge list, then sorting it, if I
> remember correctly...
>
> I have built this example code:
>
> #include <stdlib.h>
> #include "containers.h"
> #define N 10000000
> int main(void)
> {
> List *L1;
> size_t i,d;
> long long sum=0,newSum=0;
> Iterator *it;
> int *pint;
>
> L1 = iList.Create(sizeof(int));
> iList.UseHeap(L1,NULL);
> for (i=0; i<N;i++) {
> d = rand();
> sum += d;
> iList.Add(L1,&d);
This seems dangerous. iList.Add expects a pointer to an
int for the second argument, and it receives a pointer to
a size_t. What if int and size_t have different sizes?
[toc] | [prev] | [next] | [standalone]
| From | jacob navia <jacob@spamsink.net> |
|---|---|
| Date | 2012-05-27 01:13 +0200 |
| Message-ID | <jpro31$pe8$1@speranza.aioe.org> |
| In reply to | #21382 |
Le 27/05/12 00:36, Ike Naar a écrit : > This seems dangerous. iList.Add expects a pointer to an > int for the second argument, and it receives a pointer to > a size_t. What if int and size_t have different sizes? Well, the list software will read the lower sizeof(int) bytes, that's all. The other way around would be dangerous: passing a pointer to int to a size_t; But strictly speaking you are right of course. Will change that.
[toc] | [prev] | [next] | [standalone]
| From | Barry Schwarz <schwarzb@dqel.com> |
|---|---|
| Date | 2012-05-26 16:53 -0700 |
| Message-ID | <32r2s7h80h8hf2t292j7055lhgkp52e7lb@4ax.com> |
| In reply to | #21385 |
On Sun, 27 May 2012 01:13:37 +0200, jacob navia <jacob@spamsink.net> wrote: >Le 27/05/12 00:36, Ike Naar a écrit : >> This seems dangerous. iList.Add expects a pointer to an >> int for the second argument, and it receives a pointer to >> a size_t. What if int and size_t have different sizes? > >Well, the list software will read the lower sizeof(int) bytes, that's >all. And on a big-endian machine this will produce the correct value? Not to mention the mandatory diagnostic during compilation. > >The other way around would be dangerous: passing a pointer to int to a >size_t; > >But strictly speaking you are right of course. Will change that. Even casually speaking. -- Remove del for email
[toc] | [prev] | [next] | [standalone]
| From | Malcolm McLean <malcolm.mclean5@btinternet.com> |
|---|---|
| Date | 2012-05-26 16:41 -0700 |
| Message-ID | <c65696bf-c55e-4ffd-a0f3-9030ea140fcc@googlegroups.com> |
| In reply to | #21382 |
בתאריך יום שבת, 26 במאי 2012 23:36:29 UTC+1, מאת Ike Naar: > > This seems dangerous. iList.Add expects a pointer to an > int for the second argument, and it receives a pointer to > a size_t. What if int and size_t have different sizes? > Yes, size_t is a menace. I've been saying that for a while. The problem is that programmers are unwilling to use it consistently. If you want an integer, you type int.
[toc] | [prev] | [next] | [standalone]
| From | pete <pfiland@mindspring.com> |
|---|---|
| Date | 2012-05-26 22:43 -0400 |
| Message-ID | <4FC194D5.24CA@mindspring.com> |
| In reply to | #21387 |
Malcolm McLean wrote:
>
> בת×ריך ×™×•× ×©×‘×ª, 26 במ××™ 2012 23:36:29 UTC+1, מ×ת Ike Naar:
> >
> > This seems dangerous. iList.Add expects a pointer to an
> > int for the second argument, and it receives a pointer to
> > a size_t. What if int and size_t have different sizes?
> >
> Yes, size_t is a menace. I've been saying that for a while.
> The problem is that programmers are unwilling to use it consistently.
> If you want an integer, you type int.
In this case, I don't think that (size_t)
was the best choice for either (i) or (d).
(i) was counting nodes in a list
and the standard definition of what (size_t) is supposed to be,
isn't related to how many nodes can be in a list.
I think I would have used the largest unsigned integer type for (i).
(d) was assigned the return value of rand(),
so (int) is the type that would first occur to me to use for (d).
Unsigned integer types would have been the first thing
to occur to me to use for the checksums.
And even though nobody wants to see it,
this is how I would have written a program like that in C:
http://www.mindspring.com/~pfilandr/C/lists_and_files/list_lib.h
http://www.mindspring.com/~pfilandr/C/lists_and_files/list_lib.c
http://www.mindspring.com/~pfilandr/C/lists_and_files/list_type.h
/* BEGIN new.c */
#include "list_lib.h"
#include <stdio.h>
#include <stdlib.h>
#define N 1000000
#define str(s) # s
#define xstr(s) str(s)
int int_comp(const void *a, const void *b);
int
main(void)
{
int d, *d_ptr;
long unsigned i;
unsigned old_checksum = 0;
unsigned new_checksum = 0;
list_type *head = NULL;
list_type *tail = NULL;
puts("/* BEGIN output new.c */\n\nN is " xstr(N) "\n");
for (i = 0; i != N; ++i) {
d = rand();
old_checksum += d;
tail = list_append(&head, tail, &d, sizeof d);
if (tail == NULL) {
puts("tail == NULL");
printf("list only contains %lu nodes,\n\n", i);
break;
}
}
tail = head = list_sort(head, int_comp);
while (tail != NULL) {
d_ptr = tail -> data;
d = *d_ptr;
new_checksum += d;
tail = tail -> next;
if (tail != NULL && int_comp(d_ptr, tail -> data) > 0) {
puts("list is out of order\n");
break;
}
}
list_free(head, free);
head = tail = NULL;
printf("old_checksum is %lu.\n", old_checksum);
printf("new_checksum is %lu.\n", new_checksum);
puts("\n/* END output new.c */");
return 0;
}
int
int_comp(const void *a, const void *b)
{
const int *const aa = a;
const int *const bb = b;
return *bb > *aa ? -1 : *bb != *aa;
}
/* END new.c */
--
pete
[toc] | [prev] | [next] | [standalone]
| From | Malcolm McLean <malcolm.mclean5@btinternet.com> |
|---|---|
| Date | 2012-05-26 15:41 -0700 |
| Message-ID | <84d02e4d-99c3-4ef3-b505-acaf349cd9b5@googlegroups.com> |
| In reply to | #21381 |
בתאריך יום שבת, 26 במאי 2012 23:22:01 UTC+1, מאת jacob navia: > iList.Sort(L1); > Can you please send me an equivalent C++program? > You very rarely want to sort a list of integers or other atomic type. Almost always you want to sort records based on a field, or on two fields, e.g. surname followed by intials, or you want to do somethign funny, like sorting strings alphabetically but putting embedded numbers in numeric order so that fred_99 comes before fred_100.
[toc] | [prev] | [next] | [standalone]
| From | jacob navia <jacob@spamsink.net> |
|---|---|
| Date | 2012-05-27 01:14 +0200 |
| Message-ID | <jpro59$pe8$3@speranza.aioe.org> |
| In reply to | #21383 |
Le 27/05/12 00:41, Malcolm McLean a écrit : > בתאריך יום שבת, 26 במאי 2012 23:22:01 UTC+1, מאת jacob navia: >> iList.Sort(L1); >> Can you please send me an equivalent C++program? >> > You very rarely want to sort a list of integers or other atomic type. Almost always you want to sort records based on a field, or on two fields, e.g. surname followed by intials, or you want to do somethign funny, like sorting strings alphabetically but putting embedded numbers in numeric order so that fred_99 comes before fred_100. > > I know, it is just for comparing performance of ccl vs stl
[toc] | [prev] | [next] | [standalone]
| From | MelissA <melis@a.com> |
|---|---|
| Date | 2012-05-27 00:52 +0200 |
| Message-ID | <jprmr7$99b$1@news.albasani.net> |
| In reply to | #21381 |
On Sun, 27 May 2012 00:22:01 +0200
jacob navia <jacob@spamsink.net> wrote:
> Hi Ian
>
> In the c++ newsgroup you asked me for an example of the ccl
> performance It was something with building a huge list, then sorting
> it, if I remember correctly...
>
> I have built this example code:
>
> #include <stdlib.h>
> #include "containers.h"
> #define N 10000000
> int main(void)
> {
> List *L1;
> size_t i,d;
> long long sum=0,newSum=0;
> Iterator *it;
> int *pint;
>
> L1 = iList.Create(sizeof(int));
> iList.UseHeap(L1,NULL);
> for (i=0; i<N;i++) {
> d = rand();
> sum += d;
> iList.Add(L1,&d);
> }
> iList.Sort(L1);
> it = iList.NewIterator(L1);
> for (pint = it->GetFirst(it); pint; pint = it->GetNext(it)) {
> newSum += *pint;
> }
> if (sum != newSum)
> printf("Failed\n");
> else printf("Sum = %lld\n",sum);
> iList.Finalize(L1);
> }
>
> This creates a list, then fills it with 10 million random integers,
> then sorts it and verifies that all the data is still there by
> accessing all elements of the list with an iterator.
>
> Can you please send me an equivalent C++program?
>
> Thanks
Well, I have tested list sorting and traversing and quick sort
by value (doesn't change nodes order) is much faster than
standard stl list sort (which changes nodes order).
Also after sort that doesn't change nodes order, traversing
is much faster then after sort that does change nodes order.
That is of course if initial list nodes are consecutive.
Doesn't matter how much cache cpu has 512kb is enough
to show significant difference.
Greetings!
[toc] | [prev] | [next] | [standalone]
| From | Stephen Sprunk <stephen@sprunk.org> |
|---|---|
| Date | 2012-05-26 20:40 -0500 |
| Message-ID | <jps0lk$4uj$1@dont-email.me> |
| In reply to | #21381 |
On 26-May-12 17:22, jacob navia wrote: > Hi Ian > > In the c++ newsgroup you asked me for an example of the ccl performance > It was something with building a huge list, then sorting it, if I > remember correctly... Then shouldn't you have posted the response to "the c++ newsgroup" rather than comp.lang.c? > [a bunch of C++ code] Off-topic here. S -- Stephen Sprunk "God does not play dice." --Albert Einstein CCIE #3723 "God is an inveterate gambler, and He throws the K5SSS dice at every possible opportunity." --Stephen Hawking
[toc] | [prev] | [next] | [standalone]
| From | jacob navia <jacob@spamsink.net> |
|---|---|
| Date | 2012-05-27 09:32 +0200 |
| Message-ID | <jpsl9v$h39$2@speranza.aioe.org> |
| In reply to | #21390 |
Le 27/05/12 03:40, Stephen Sprunk a écrit : >> [a bunch of C++ code] Why is it C++? It compiles with every C compiler you can choose... Never mind, don't let facts disturb your beliefs.
[toc] | [prev] | [next] | [standalone]
| From | pete <pfiland@mindspring.com> |
|---|---|
| Date | 2012-05-27 07:18 -0400 |
| Message-ID | <4FC20D7F.7E39@mindspring.com> |
| In reply to | #21396 |
jacob navia wrote: > > Le 27/05/12 03:40, Stephen Sprunk a écrit : > >> [a bunch of C++ code] > > Why is it C++? He probably didn't know what "containers.h" was. > It compiles with every C compiler you can choose... > > Never mind, don't let facts disturb your beliefs. -- pete
[toc] | [prev] | [next] | [standalone]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Date | 2012-05-27 14:24 +1200 |
| Message-ID | <a2dhipF7faU1@mid.individual.net> |
| In reply to | #21381 |
On 05/27/12 10:22 AM, jacob navia wrote:
> Hi Ian
>
> In the c++ newsgroup you asked me for an example of the ccl performance
> It was something with building a huge list, then sorting it, if I
> remember correctly...
>
> I have built this example code:
>
> #include<stdlib.h>
> #include "containers.h"
> #define N 10000000
> int main(void)
> {
> List *L1;
> size_t i,d;
> long long sum=0,newSum=0;
> Iterator *it;
> int *pint;
All good code should have at least one beer reference!
It be a lot easier to see what is what if these were declared on first use.
> L1 = iList.Create(sizeof(int));
> iList.UseHeap(L1,NULL);
> for (i=0; i<N;i++) {
> d = rand();
> sum += d;
> iList.Add(L1,&d);
> }
> iList.Sort(L1);
> it = iList.NewIterator(L1);
> for (pint = it->GetFirst(it); pint; pint = it->GetNext(it)) {
> newSum += *pint;
> }
> if (sum != newSum)
> printf("Failed\n");
> else printf("Sum = %lld\n",sum);
> iList.Finalize(L1);
> }
>
> This creates a list, then fills it with 10 million random integers,
> then sorts it and verifies that all the data is still there by
> accessing all elements of the list with an iterator.
>
> Can you please send me an equivalent C++program?
I did (with the addition of using one list to initialise another) in the
c.l.c++ thread you should have posted this in response to.
--
Ian Collins
[toc] | [prev] | [next] | [standalone]
| From | "BartC" <bc@freeuk.com> |
|---|---|
| Date | 2012-05-27 10:36 +0100 |
| Message-ID | <jpssi6$tf0$2@dont-email.me> |
| In reply to | #21391 |
"Ian Collins" <ian-news@hotmail.com> wrote in message
news:a2dhipF7faU1@mid.individual.net...
> On 05/27/12 10:22 AM, jacob navia wrote:
>> Hi Ian
>>
>> In the c++ newsgroup you asked me for an example of the ccl performance
>> It was something with building a huge list, then sorting it, if I
>> remember correctly...
>>
>> I have built this example code:
>>
>> #include<stdlib.h>
>> #include "containers.h"
>> #define N 10000000
>> int main(void)
>> {
>> List *L1;
>> size_t i,d;
>> long long sum=0,newSum=0;
>> Iterator *it;
>> int *pint;
>
> All good code should have at least one beer reference!
>
> It be a lot easier to see what is what if these were declared on first
> use.
As in, instead of reading a play which starts with a cast of characters,
they should be introduced whenever they first appear?
Suppose you're delving into a random scene, (or have an extract for use
elsewhere), and want to be reminded who a character is, you have to start
ploughing through from page one first until you encounter their first
mention?
And if you are editing the play, and the character's first appearance is
edited out, or is moved somewhere where it's no longer the first appearance;
how much work is it going to be to fix up declarations properly?
Getting back to C, wouldn't macros and enumerations (and file-scope
variables, external references, etc) also all benefit from being declared
where they are first used? (And what sort of mess would that make of any
program...).
Anyway I thought everyone used smart editors now, where you hover over a
name or something, and it tells you everything about it.
--
Bartc
[toc] | [prev] | [next] | [standalone]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Date | 2012-05-27 22:33 +1200 |
| Message-ID | <a2ee73F7faU5@mid.individual.net> |
| In reply to | #21403 |
On 05/27/12 09:36 PM, BartC wrote:
>
>
> "Ian Collins"<ian-news@hotmail.com> wrote in message
> news:a2dhipF7faU1@mid.individual.net...
>> On 05/27/12 10:22 AM, jacob navia wrote:
>>> Hi Ian
>>>
>>> In the c++ newsgroup you asked me for an example of the ccl performance
>>> It was something with building a huge list, then sorting it, if I
>>> remember correctly...
>>>
>>> I have built this example code:
>>>
>>> #include<stdlib.h>
>>> #include "containers.h"
>>> #define N 10000000
>>> int main(void)
>>> {
>>> List *L1;
>>> size_t i,d;
>>> long long sum=0,newSum=0;
>>> Iterator *it;
>>> int *pint;
>>
>> All good code should have at least one beer reference!
>>
>> It be a lot easier to see what is what if these were declared on first
>> use.
>
> As in, instead of reading a play which starts with a cast of characters,
> they should be introduced whenever they first appear?
>
> Suppose you're delving into a random scene, (or have an extract for use
> elsewhere), and want to be reminded who a character is, you have to start
> ploughing through from page one first until you encounter their first
> mention?
A function is more like a limerick than a play.
> And if you are editing the play, and the character's first appearance is
> edited out, or is moved somewhere where it's no longer the first appearance;
> how much work is it going to be to fix up declarations properly?
No a lot.
> Getting back to C, wouldn't macros and enumerations (and file-scope
> variables, external references, etc) also all benefit from being declared
> where they are first used? (And what sort of mess would that make of any
> program...).
I would make them longer, unlike declaring variables when they are
needed makes them shorter. Besides, how do you introduce a const other
that where it is initialised?
> Anyway I thought everyone used smart editors now, where you hover over a
> name or something, and it tells you everything about it.
Alas, Thunderbird lack that feature.
--
Ian Collins
[toc] | [prev] | [next] | [standalone]
| From | "BartC" <bc@freeuk.com> |
|---|---|
| Date | 2012-05-27 12:25 +0100 |
| Message-ID | <jpt30f$sdq$1@dont-email.me> |
| In reply to | #21405 |
"Ian Collins" <ian-news@hotmail.com> wrote in message news:a2ee73F7faU5@mid.individual.net... > On 05/27/12 09:36 PM, BartC wrote: >> "Ian Collins"<ian-news@hotmail.com> wrote in message >>> It be a lot easier to see what is what if these were declared on first >>> use. >> >> As in, instead of reading a play which starts with a cast of characters, >> they should be introduced whenever they first appear? >> >> Suppose you're delving into a random scene, (or have an extract for use >> elsewhere), and want to be reminded who a character is, you have to start >> ploughing through from page one first until you encounter their first >> mention? > > A function is more like a limerick than a play. In that case I can't see it being a big imposition if the names were declared at the top of the function (ie. at the top of the screen if a function is small). Then it gets the clutter out of the code. And all uses of the name are identical (instead of one of them needing a declaration). Although, it will make the function a bit longer.. >> Getting back to C, wouldn't macros and enumerations .... also >> all benefit from being declared where they are first used? > I would make them longer, unlike declaring variables when they are needed > makes them shorter. That's another thing; uses of i, j and k for loop indices is fairly standard. They probably will be ints, and the formality of having to declare them can be kept out of the way instead of making for-loops even longer. (Alternatively for-loop variables could be implicitly declared.) > Besides, how do you introduce a const other that where it is initialised? What do you mean by a const? If it is a name that is to be used in several places, then it can also benefit from splitting declaration (and initialisation) from it's use. It gets more complicated when declarations in blocks are used (which apparently have their own name spaces). But I've never used those, and if functions are small as everyone says they should be, I can't see the need. (Of course my point of view is from reading code rather than writing it. But the former should have priority.) -- Bartc
[toc] | [prev] | [next] | [standalone]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Date | 2012-05-28 07:17 +1200 |
| Message-ID | <a2fcuvF7faU6@mid.individual.net> |
| In reply to | #21409 |
On 05/27/12 11:25 PM, BartC wrote: > "Ian Collins"<ian-news@hotmail.com> wrote in message > news:a2ee73F7faU5@mid.individual.net... >> On 05/27/12 09:36 PM, BartC wrote: > >>> Getting back to C, wouldn't macros and enumerations .... also >>> all benefit from being declared where they are first used? > >> I would make them longer, unlike declaring variables when they are needed >> makes them shorter. > > That's another thing; uses of i, j and k for loop indices is fairly > standard. They probably will be ints, and the formality of having to declare > them can be kept out of the way instead of making for-loops even longer. > (Alternatively for-loop variables could be implicitly declared.) Declaring loop indexes in the loop makes it clear that's what they are and that they won't spill out. >> Besides, how do you introduce a const other that where it is initialised? > > What do you mean by a const? If it is a name that is to be used in several > places, then it can also benefit from splitting declaration (and > initialisation) from it's use. const in t n = some_expression; -- Ian Collins
[toc] | [prev] | [next] | [standalone]
| From | Ike Naar <ike@sverige.freeshell.org> |
|---|---|
| Date | 2012-05-27 13:03 +0000 |
| Message-ID | <slrn3vfsjs49hd.l5c.ike@sverige.freeshell.org> |
| In reply to | #21403 |
On 2012-05-27, BartC <bc@freeuk.com> wrote: > Suppose you're delving into a random scene, (or have an extract for use > elsewhere), and want to be reminded who a character is, you have to start > ploughing through from page one first until you encounter their first > mention? It depends. When a variable is declared on first use, the active scope of the variable is sometimes reduced to a few lines of code. So, to find the declaration, one has to plough backward for a few lines. That may take less ploughing than when the declaration is at the beginning of the function.
[toc] | [prev] | [next] | [standalone]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Date | 2012-05-27 15:16 +1200 |
| Message-ID | <a2dkjvF7faU2@mid.individual.net> |
| In reply to | #21381 |
On 05/27/12 10:22 AM, jacob navia wrote:
> Hi Ian
>
> In the c++ newsgroup you asked me for an example of the ccl performance
> It was something with building a huge list, then sorting it, if I
> remember correctly...
>
> I have built this example code:
>
<snip>
I get a segv when I run the example. Running in dbx with access
checking enabled shows:
Write to unallocated (wua):
Attempting to write 1 byte at address 0x8091d88
which is just past heap block of size 800 bytes at 0x8091a68
This block was allocated from:
newHeapObject<-NewLink<-Add_nd<-Add<-main
Location of error: heap.c, line 75, newHeapObject()
The offending code appears to be here in heap.c:
/* The array of block pointers is full. Allocate CHUNK_SIZE blocks
more */
siz = (l->BlockCount+CHUNK_SIZE)*sizeof(ListElement *);
result = l->Allocator->realloc(l->Heap,siz);
if (result == NULL) {
return NULL;
}
l->MemoryUsed+= siz;
l->Heap = (char **)result;
/* Position pointer at the start of the new area */
result += l->BlockCount*sizeof(ListElement *);
/* Zero the new pointers */
memset(result,0,siz);
It looks like you are allocating siz byes, incrementing part (half) way
through the bock then zeroing the next siz bytes.
--
Ian Collins
[toc] | [prev] | [next] | [standalone]
| From | jacob navia <jacob@spamsink.net> |
|---|---|
| Date | 2012-05-27 09:30 +0200 |
| Message-ID | <jpsl62$h39$1@speranza.aioe.org> |
| In reply to | #21393 |
Le 27/05/12 05:16, Ian Collins a écrit : > On 05/27/12 10:22 AM, jacob navia wrote: >> Hi Ian >> >> In the c++ newsgroup you asked me for an example of the ccl performance >> It was something with building a huge list, then sorting it, if I >> remember correctly... >> >> I have built this example code: >> > <snip> > > I get a segv when I run the example. Running in dbx with access checking > enabled shows: I corrected that yesterday. When you asked me gthis example I was in the middle of a reorganization of heap.c. Look at the latest update
[toc] | [prev] | [next] | [standalone]
Page 1 of 3 [1] 2 3 Next page →
Back to top | Article view | comp.lang.c
csiph-web