Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #24534

Re: Are Computer able to think?

From Paul Rubin <no.email@nospam.invalid>
Newsgroups comp.lang.forth
Subject Re: Are Computer able to think?
Date 2013-07-16 23:24 -0700
Organization Nightsong/Fort GNOX
Message-ID <7xhaftya8u.fsf@ruckus.brouhaha.com> (permalink)
References (5 earlier) <krv0i6$i3r$1@speranza.aioe.org> <7xppuk25y4.fsf@ruckus.brouhaha.com> <krv88g$6iu$1@speranza.aioe.org> <7xk3ks3go6.fsf@ruckus.brouhaha.com> <ks25rn$lr7$1@speranza.aioe.org>

Show all headers | View raw


"Rod Pemberton" <do_not_have@notemailnotq.cpm> writes:
>> How would you code std::shared_ptr in C?
> Sorry, I have no idea what that is.  
> If you explain it, perhaps I can tell you the C equivalent. 

Leaving aside refinements like counting weak pointers, a shared_ptr is a
pointer combined with a reference count, e.g. (I may have the syntax
slightly garbled, I don't use C++ much):

   typedef class { ... stuff ... } Foo;
   typedef std::shared_ptr<Foo> Foo_ptr;

   Foo_ptr p(2,3,4);

creates a shared Foo pointer p, initialized with 2,3,4, and the
reference count is 1, with the storage from the Foo structure allocated
by something like malloc.  If you now say

   Foo_ptr q = p;

that copies the pointer from p to q, and increments the ref count.  That
works because the shared_ptr definition overloads the = operator.  Same
thing happens if you have a Foo_ptr in the middle of some structure and
you copy the structure.  And then, because shared_ptrs have destructors,
when something containing a Foo_ptr goes out of scope (by functions
returning or by exceptions being thrown), the ref count is decremented.
If the ref count goes to zero, the storage is freed.  That means the
compiler has to pervasively track these things all through your program,
maybe 1000's of modules or whatever.  At the same time, it's quite easy
to introduce them into existing programs that don't already use them.
You don't have to write the whole program in some contorted style just
to deal with some program-specific scheme.

Of course this is all pretty crufty in its own right and precise GC is
preferable most of the time, but nonetheless it is observably workable
and is apparently now the preferred C++ approach to shared pointers,
i.e., manual use of new/delete (basically malloc/free) is now somewhat
deprecated.

> Or, perhaps, it's just not needed in C. 

That's a cop-out.  People use it, and if doing without it makes
development more cumbersome, that can make C an unsatisfactory answer.

Back to comp.lang.forth | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Are Computer able to think? visualforth@rocketmail.com - 2013-07-12 06:18 -0700
  Re: Are Computer able to think? Alex McDonald <blog@rivadpm.com> - 2013-07-12 07:42 -0700
  Re: Are Computer able to think? Jason Damisch <jasondamisch@yahoo.com> - 2013-07-12 12:33 -0700
    Re: Are Computer able to think? Jason Damisch <jasondamisch@yahoo.com> - 2013-07-12 12:46 -0700
      Re: Are Computer able to think? Brad Eckert <hwfwguy@gmail.com> - 2013-07-12 14:28 -0700
        Re: Are Computer able to think? Jason Damisch <jasondamisch@yahoo.com> - 2013-07-12 14:50 -0700
          Re: Are Computer able to think? albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-07-18 11:36 +0000
            Re: Are Computer able to think? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-07-18 07:31 -0500
              Re: Are Computer able to think? Bernd Paysan <bernd.paysan@gmx.de> - 2013-07-18 23:41 +0200
  Re: Are Computer able to think? Bernd Paysan <bernd.paysan@gmx.de> - 2013-07-13 02:52 +0200
    Re: Are Computer able to think? hughaguilar96@yahoo.com - 2013-07-12 20:06 -0700
      Re: Are Computer able to think? Bernd Paysan <bernd.paysan@gmx.de> - 2013-07-13 14:34 +0200
        Re: Are Computer able to think? hughaguilar96@yahoo.com - 2013-07-13 19:54 -0700
          Re: Are Computer able to think? albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-07-14 11:32 +0000
            Re: Are Computer able to think? Paul Rubin <no.email@nospam.invalid> - 2013-07-14 11:46 -0700
          Re: Are Computer able to think? hughaguilar96@yahoo.com - 2013-07-14 21:57 -0700
    Re: Are Computer able to think? hughaguilar96@yahoo.com - 2013-07-12 20:44 -0700
      Re: Are Computer able to think? Bernd Paysan <bernd.paysan@gmx.de> - 2013-07-13 14:37 +0200
  Re: Are Computer able to think? hughaguilar96@yahoo.com - 2013-07-12 20:08 -0700
  Re: Are Computer able to think? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-07-13 01:44 -0500
    Re: Are Computer able to think? Hans Bezemer <the.beez.speaks@gmail.com> - 2013-07-13 22:25 +0200
  Re: Are Computer able to think? "Rod Pemberton" <do_not_have@notemailnotq.cpm> - 2013-07-13 06:15 -0400
    Re: Are Computer able to think? visualforth@rocketmail.com - 2013-07-13 11:31 -0700
      Re: Are Computer able to think? "Rod Pemberton" <do_not_have@notemailnotq.cpm> - 2013-07-13 19:31 -0400
        Re: Are Computer able to think? visualforth@rocketmail.com - 2013-07-13 18:17 -0700
          Re: Are Computer able to think? "Rod Pemberton" <do_not_have@notemailnotq.cpm> - 2013-07-14 16:11 -0400
            Re: Are Computer able to think? Paul Rubin <no.email@nospam.invalid> - 2013-07-14 14:21 -0700
              Re: Are Computer able to think? visualforth@rocketmail.com - 2013-07-14 15:03 -0700
                Re: Are Computer able to think? hughaguilar96@yahoo.com - 2013-07-14 21:51 -0700
                Re: Are Computer able to think? visualforth@rocketmail.com - 2013-07-15 00:09 -0700
                Re: Are Computer able to think? Paul Rubin <no.email@nospam.invalid> - 2013-07-15 02:39 -0700
                Re: Are Computer able to think? visualforth@rocketmail.com - 2013-07-17 04:21 -0700
                Re: Are Computer able to think? "Elizabeth D. Rather" <erather@forth.com> - 2013-07-17 07:31 -1000
                Re: Are Computer able to think? visualforth@rocketmail.com - 2013-07-17 12:06 -0700
                Re: Are Computer able to think? hughaguilar96@yahoo.com - 2013-07-17 23:53 -0700
                Re: Are Computer able to think? Paul Rubin <no.email@nospam.invalid> - 2013-07-18 22:23 -0700
                Re: Are Computer able to think? visualforth@rocketmail.com - 2013-07-19 00:48 -0700
              Re: Are Computer able to think? "Rod Pemberton" <do_not_have@notemailnotq.cpm> - 2013-07-14 18:22 -0400
                Re: Are Computer able to think? Paul Rubin <no.email@nospam.invalid> - 2013-07-14 15:44 -0700
                Re: Are Computer able to think? "Rod Pemberton" <do_not_have@notemailnotq.cpm> - 2013-07-15 21:00 -0400
                Re: Are Computer able to think? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-07-16 03:43 -0500
                Re: Are Computer able to think? Paul Rubin <no.email@nospam.invalid> - 2013-07-16 23:24 -0700
                Re: Are Computer able to think? The Beez <the.beez.speaks@gmail.com> - 2013-07-16 07:24 -0700
                Re: Are Computer able to think? Hans Bezemer <the.beez.speaks@gmail.com> - 2013-07-16 23:41 +0200
                Re: Are Computer able to think? Paul Rubin <no.email@nospam.invalid> - 2013-07-16 19:16 -0700
                Re: Are Computer able to think? AKK <akk@nospam.org> - 2013-07-17 08:04 +0200
                Re: Are Computer able to think? Paul Rubin <no.email@nospam.invalid> - 2013-07-16 23:27 -0700
                Re: Are Computer able to think? "Elizabeth D. Rather" <erather@forth.com> - 2013-07-16 20:48 -1000
                Re: Are Computer able to think? Hans Bezemer <the.beez.speaks@gmail.com> - 2013-07-17 11:51 +0200
                Re: Are Computer able to think? Alex McDonald <blog@rivadpm.com> - 2013-07-17 04:49 -0700
                Re: Are Computer able to think? The Beez <the.beez.speaks@gmail.com> - 2013-07-18 07:15 -0700
                Re: Are Computer able to think? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-07-18 11:59 -0500
                Re: Are Computer able to think? Hans Bezemer <the.beez.speaks@gmail.com> - 2013-07-18 21:56 +0200
                Re: Are Computer able to think? Bernd Paysan <bernd.paysan@gmx.de> - 2013-07-18 23:45 +0200
                Re: Are Computer able to think? Alex McDonald <blog@rivadpm.com> - 2013-07-18 15:16 -0700
                Re: Are Computer able to think? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-07-18 17:40 -0500
                Re: Are Computer able to think? Bernd Paysan <bernd.paysan@gmx.de> - 2013-07-19 01:08 +0200
                Re: Are Computer able to think? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-07-19 02:48 -0500
                Re: Are Computer able to think? Mark Wills <markrobertwills@yahoo.co.uk> - 2013-07-19 01:18 -0700
                Re: Are Computer able to think? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-07-19 03:35 -0500
                Re: Are Computer able to think? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-07-22 09:50 +0000
                Re: Are Computer able to think? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-07-18 17:32 -0500
                Re: Are Computer able to think? Hans Bezemer <the.beez.speaks@gmail.com> - 2013-07-19 19:28 +0200
                Re: Are Computer able to think? Paul Rubin <no.email@nospam.invalid> - 2013-07-19 10:51 -0700
                Re: Are Computer able to think? Hans Bezemer <the.beez.speaks@gmail.com> - 2013-07-20 00:34 +0200
                Re: Are Computer able to think? Paul Rubin <no.email@nospam.invalid> - 2013-07-19 23:08 -0700
                Re: Are Computer able to think? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-07-20 05:49 -0500
                Re: Are Computer able to think? Jason Damisch <jasondamisch@yahoo.com> - 2013-07-20 06:21 -0700
                Re: Are Computer able to think? Brad Eckert <hwfwguy@gmail.com> - 2013-07-20 14:02 -0700
                Re: Are Computer able to think? Paul Rubin <no.email@nospam.invalid> - 2013-07-20 17:02 -0700
                Re: Are Computer able to think? visualforth@rocketmail.com - 2013-07-21 10:02 -0700
                Re: Are Computer able to think? Jason Damisch <jasondamisch@yahoo.com> - 2013-07-21 10:07 -0700
                Re: Are Computer able to think? Hannu Vuolasaho <hannu.vuolasaho@nospam.tut.fi.invalid> - 2013-07-21 19:23 +0000
                Re: Are Computer able to think? Lars Brinkhoff <lars.spam@nocrew.org> - 2013-07-20 10:07 +0200
                Re: Are Computer able to think? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-07-19 18:16 -0500
                Re: Are Computer able to think? Alex McDonald <blog@rivadpm.com> - 2013-07-18 15:09 -0700
                Re: Are Computer able to think? Paul Rubin <no.email@nospam.invalid> - 2013-07-17 10:46 -0700
                Re: Are Computer able to think? Hans Bezemer <the.beez.speaks@gmail.com> - 2013-07-18 00:40 +0200
                Re: Are Computer able to think? Paul Rubin <no.email@nospam.invalid> - 2013-07-17 21:34 -0700
                Re: Are Computer able to think? hughaguilar96@yahoo.com - 2013-07-17 23:55 -0700
                Re: Are Computer able to think? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-07-18 13:03 -0500
                Re: Are Computer able to think? Hans Bezemer <the.beez.speaks@gmail.com> - 2013-07-18 22:00 +0200
                Re: Are Computer able to think? The Beez <the.beez.speaks@gmail.com> - 2013-07-18 07:21 -0700
                Re: Are Computer able to think? Paul Rubin <no.email@nospam.invalid> - 2013-07-18 11:02 -0700
                Re: Are Computer able to think? Hans Bezemer <the.beez.speaks@gmail.com> - 2013-07-18 22:02 +0200
                Re: Are Computer able to think? Paul Rubin <no.email@nospam.invalid> - 2013-07-18 21:43 -0700
                Re: Are Computer able to think? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-07-17 03:29 -0500
              Re: Are Computer able to think? hughaguilar96@yahoo.com - 2013-07-14 21:44 -0700
                Re: Are Computer able to think? Bernd Paysan <bernd.paysan@gmx.de> - 2013-07-15 16:45 +0200
                Re: Are Computer able to think? hughaguilar96@yahoo.com - 2013-07-15 20:32 -0700
  Re: Are Computer able to think? mentifex@myuw.net - 2013-07-14 11:52 -0700
  Re: Are Computer able to think? Mark Wills <markrobertwills@yahoo.co.uk> - 2013-07-17 05:24 -0700
  Re: Are Computer able to think? albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-07-18 11:15 +0000
    Re: Are Computer able to think? Brad Eckert <hwfwguy@gmail.com> - 2013-07-18 11:33 -0700
  Re: Are Computer able to think? jim@rainbarrel.com - 2013-07-24 20:09 -0700
    Re: Are Computer able to think? m.a.m.hendrix@tue.nl - 2013-07-25 00:15 -0700
    Re: Are Computer able to think? Brad Eckert <hwfwguy@gmail.com> - 2013-07-25 08:38 -0700

csiph-web