On 2 April 2012 14:27, Stuart Dallas <stu...@3ft9.com> wrote:

> On 2 Apr 2012, at 14:12, Simon wrote:
> > Thanks Maciek
> >
> > On 2 April 2012 10:37, Maciek Sokolewicz <maciek.sokolew...@gmail.com
> >wrote:
> >
> >> On 02-04-2012 10:12, Simon wrote:
> >>
> >>> Thanks Simon. you got my hopes up there for a second.
> >>>
> >>> From the php docs page:
> >>>
> >>> Critics further argue that it is pointless to use a Singleton in a
> Shared
> >>>>
> >>> Nothing Architecture like PHP where objects are unique>within the
> Request
> >>> only anyways.
> >>>
> >>> I want the the singleton class to be global to the entire application
> (ie
> >>> shared "by reference" across all requests). I'd agree with the above
> >>> critics that if you have to instantiate your singleton for each
> request,
> >>> it's rather pointless.
> >>>
> >>> Well, that's simply not possible due to the "shared nothing paradigm".
> >> If you want to share, you need to either share it via another medium
> (such
> >> as a database, as has been suggested a dozen times already) or switch
> to a
> >> different language.
> >
> >
> >
> >> PHP is based on this paradigm, and you should not expect of it to
> violate
> >> it just because you want to do things a certain way, which is not the
> >> way.
> >>
> >
> > The existence of memcached, shm and apc_fetch tell me that PHP already
> > accepts the need for sharing data between processes. All I'm arguing for
> is
> > the ability to share the data by reference rather than by copy.
> As already mentioned several times the closest you will get is shared
> memory (as used by APC), but you can't access that by reference because
> shared read/write resources need controlled access for stability.

I know. I understand that (and the issues with locking that might arise if
truly shared memory was available).

> I can't find any material that explains how the .net framework implements
> application variables. You mentioned earlier that you *know* that when you
> access them you do so by reference. Do you have a source for this knowledge
> or is it some sort of sixth sense?

Source: 10+ years as an ASP and ASP.NET developer.

Having looked for documentation, I agree, it's utterly terrible. It's as if
even Microsoft themselves don't fully understand the advantages that
application variables give them over the competition. (Though they're
hardly likely to be forthcoming about helping others implement similar

Here's some stuff I did find:

This article explains basically how application variables work. It doesn't
specifically mention passing by reference but it discusses thread safety at
some length so you might infer that implies passing by reference.

Here is a more technical discussion about the singleton class is
implemented in .NET. Application variables are provided by an instance of a
singleton class (the HttpApplication class).

Stack overflow question from someone actually wanting to get a *copy* of an
application variable rather than a reference.

So, if you read enough of this stuff, you'll find out that a .NET website
(an IIS application in MS parlance) runs in a multi-threaded single
process. Application variables (and singleton classes) are shared by
reference between all threads. It is possible to run an IIS application
over multiple processes (to take advantage of multiple processors / server
farms for example) but then the Application variables are not shared at
all. (This is then pretty comparable to the situation with node.js except
that node is not multi-threaded)

> I would not feel comfortable having my code creating multiple pointers to
> a read/write segment of shared memory that then uncontrollably float around
> umpteen processes. If MS have something akin to this in .net I would be
> extremely interested in reading about how it works without imploding.
> -Stuart
> --
> Stuart Dallas
> 3ft9 Ltd
> http://3ft9.com/

Reply via email to