Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Steve Thompson <stevet810@gmail.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Compatibility question |
| Date | 2012-10-22 23:27 +0000 |
| Organization | Friends of the Galactic Collective |
| Message-ID | <9vtC6c.NDd.KogKS@gmail.com> (permalink) |
| References | (5 earlier) <0.a87a1c8a472d870b0466.20121022022701BST.87y5izxpne.fsf@bsb.me.uk> <JLOhFS.Dvd.FY9Iy@gmail.com> <0.d779297035d2edccd1b4.20121022173052BST.87ehkqbhab.fsf@bsb.me.uk> <2nYjPo.Krd.2aRbe@gmail.com> <90b3a525-f709-4638-b566-25480c865799@googlegroups.com> |
On Mon, Oct 22, 2012 at 02:23:59PM -0700, Öö Tiib wrote:
> On Monday, 22 October 2012 20:29:11 UTC+3, Steve Thompson wrote:
> > When I was
> > less experienced with C, I was confused by the fact that variables
> > defined as structures were not pointers:
> >
> > struct point {
> > int x, y, z;
> > };
> >
> > struct point a;
> >
> >
> > One cannot reference 'a' (as such) in an expression even though it is
> > a pointer in the implementation because C allows one to use structures
> > as arguments to a function.
>
> One can use 'a' as such in several expressions like '(void)a', '&a', 'sizeof(a)' and 'a.x'.
>
> > I'd never do that in my own code, but
> > some people may like the fact that they can pass complex data
> > structures around as if they were simple variables.
>
> Anything that contains less than 32 bytes of information is very small amount
> of data in modern PC and so is usually optimal to use it by value as whole
> instead of making dynamic memory allocations for it. Passing by value
> makes it impossible for callee to modify the data of caller so it is safer.
> That is especially important in situations of concurrency. It is safer
> to pass data between different threads copied, then each has his own copy
> and there can not be any race conditions.
There's lots of room for argument in that . All that can be said is
that it depends. It depends on the kind of data being passed around,
and what's being done with it. In terms of concurrency, I suggest it
would be rare to see the same data making the rounds in a bunch of
different threads, but of course YMMV. In the case where you have
small data objects, making copies of them is no big deal unless you
have millions or billions of them. A properly written program will
modify only the data it is supposed to change; anything else is a bug.
I can use four of the 32 bytes that you'd copy and instantiate a
lightweight r/w lock that would absolutely guarantee consistency for
that object.
> > I think it wastes resources, but of course that is less of an issue today
> > than it was when C was first developed.
>
> Dynamic memory management is what wastes most of resources these days. OOP
> languages like Java and C++ rely sometimes too heavily on dynamic allocations
> of little objects and that makes them inefficient when the whole amount of
> such data grows into very large. For example: just 1000 cycles within 1000
> cycles and little allocations/deallocations done in that inner cycle. That
> takes about 5 seconds. 1000 by 1000 is very little however these days.
> Everybody have gigabytes of memory, terabyte of hard drive and millions of pixels on screen.
I'm taking some pains to make allocations very speedy, but the problem
you are describing likely results from all those small objects being
copied as a consequence of the implementation of those languages.
Regards,
Steve Thompson
--
GOTO's are like guns. Safety is entirely contingent on the user.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-20 03:08 +0000
Re: Compatibility question Ian Collins <ian-news@hotmail.com> - 2012-10-20 16:20 +1300
Re: Compatibility question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-20 11:50 +0100
Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-20 11:41 -0700
Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-21 23:04 +0000
Re: Compatibility question Barry Schwarz <schwarzb@dqel.com> - 2012-10-21 20:27 -0700
Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-20 04:01 +0000
Re: Compatibility question Ian Collins <ian-news@hotmail.com> - 2012-10-21 09:26 +1300
Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-21 22:54 +0000
Re: Compatibility question Ian Collins <ian-news@hotmail.com> - 2012-10-22 12:29 +1300
Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-21 23:50 +0000
Re: Compatibility question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-22 02:27 +0100
Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-22 02:28 +0000
Re: Compatibility question Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-10-22 11:18 -0400
Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-22 16:19 +0000
Re: Compatibility question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-22 17:37 +0100
Re: Compatibility question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-22 17:40 +0100
Re: Compatibility question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-22 17:30 +0100
Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-22 17:23 +0000
Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-22 10:52 -0700
Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-22 18:42 +0000
Re: Compatibility question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-22 21:06 +0100
Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-22 22:52 +0000
Re: Compatibility question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-23 03:33 +0100
Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-23 12:28 +0000
Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-23 16:45 +0100
Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-23 17:53 +0000
Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-23 12:41 -0700
Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-23 21:28 +0100
Re: Compatibility question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-23 20:57 +0100
Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-23 12:26 -0700
Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-23 20:39 +0000
Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-23 15:53 -0700
Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-24 00:57 +0100
Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-23 20:06 -0700
Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-24 11:18 +0100
Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-24 12:04 -0700
Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-24 23:10 +0100
Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-24 16:58 -0700
Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-25 01:46 +0100
Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-24 19:40 -0700
Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-24 20:20 +0000
Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-24 14:38 -0700
Re: Compatibility question James Kuyper <jameskuyper@verizon.net> - 2012-10-24 17:55 -0400
Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-24 16:29 -0700
Re: Compatibility question Greg Martin <greg@softsprocket.com> - 2012-10-24 15:21 -0700
Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-26 03:30 +0000
Re: Compatibility question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-26 13:02 +0100
Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-27 00:04 +0000
Re: Compatibility question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-27 20:15 +0100
Re: Compatibility question Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2012-10-27 16:36 -0600
Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-28 17:36 +0000
Re: Compatibility question Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2012-10-27 22:42 +0300
Re: Compatibility question Greg Martin <greg@softsprocket.com> - 2012-10-27 14:30 -0700
Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-27 22:57 +0100
Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-27 17:04 -0700
Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-27 17:14 -0700
Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-27 18:04 -0700
Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-24 16:46 -0700
Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-25 01:18 +0000
Re: Compatibility question Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2012-10-27 21:08 +0300
Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-28 17:38 +0000
Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-23 00:38 +0100
Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-22 16:50 -0700
Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-23 12:33 +0000
Re: Compatibility question Öö Tiib <ootiib@hot.ee> - 2012-10-22 14:23 -0700
Re: Compatibility question James Kuyper <jameskuyper@verizon.net> - 2012-10-22 17:26 -0400
Re: Compatibility question Ian Collins <ian-news@hotmail.com> - 2012-10-23 10:55 +1300
Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-22 23:27 +0000
Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-22 22:44 +0100
Re: Compatibility question Les Cargill <lcargill99@comcast.com> - 2012-10-22 17:15 -0500
Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-23 00:13 +0100
Re: Compatibility question James Kuyper <jameskuyper@verizon.net> - 2012-10-22 18:35 -0400
Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-23 00:14 +0100
Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-22 23:42 +0000
Re: Compatibility question Ian Collins <ian-news@hotmail.com> - 2012-10-23 13:35 +1300
Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-22 17:01 -0700
Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-23 01:47 +0100
Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-21 19:27 -0700
csiph-web