 |
|
| Computers Forum Index » Computer Languages (Misc) » New release of the Dynace OO extension to C... |
|
Page 1 of 8 Goto page 1, 2, 3, 4, 5, 6, 7, 8 Next |
|
| Author |
Message |
| Blake McBride... |
Posted: Tue Jul 14, 2009 12:10 am |
|
|
|
Guest
|
A new release of Dynace is available at: http://blake.mcbride.name
This release has a new port to the Mac and updated support for Wine.
Dynace is an open source, OO extension to C that gives C (or C++), a
full meta-object protocol, and multiple inheritance. Dynace is designed
to solve many of the problems associated with C++ while being easier to
learn and containing more flexible object oriented facilities. Dynace is
able to add facilities previously only available in languages such as
Smalltalk and CLOS without all the overhead normally associated with
those environments.
The Dynace system also includes a GUI development system that runs under
Win32 or Wine (Linux, etc.).
Dynace runs on:
Windows
Apple Mac
Linux
FreeBSD
OpenSolaris
Blake McBride |
|
|
| Back to top |
|
|
|
| ld... |
Posted: Tue Jul 14, 2009 7:45 pm |
|
|
|
Guest
|
On 14 juil, 20:42, Juha Nieminen <nos... at (no spam) thanks.invalid> wrote:
Quote: In C++, since the compiler sees the entire class structure, making a
virtual function call is basically reading a function address from a
fixed offset in the virtual table, and jumping to that address. If,
however, the compiler would not see the class structure, it has no way
of knowing from the opaque pointer what this offset might be, without
doing more elaborate operations to resolve it.
But these operations could be as fast as you mentioned, specially on
modern architectures. In fact, as soon as you consider single
inheritance, what you say is true: it's almost impossible to beat C++
virtual call. But in real programs, your concrete classes will derive
from more than one abstract class (interfaces) to ensure better
flexibility, and multiple inheritance requires offsets adjustment
which is mainly sequential even on modern arch:
obj->vtable->fun( obj + obj->vtable->offset )
Moreover, if you use virtual inheritance (as you should for
interfaces), more than one offset adjustment will occur. In the end,
compared to a well designed dispatcher, you will get something running
more or less at the same speed as C++ virtual call (on modern arch).
I did some measurements for COS (C Object System) vs C++ vs Objective-
C. The results are described in the following papers in page 9 for
http://cos.cvs.sourceforge.net/viewvc/cos/doc/cos_draft-dls09.pdf.gz
and in page 14 for
http://cos.cvs.sourceforge.net/viewvc/cos/doc/cos_draft-oopsla09.pdf.gz
The conclusion is that dynamic dispatch (lookup) can be as fast as
late dispatch (vtable) because most of the operations can be
parallelized on modern cpu (thanks to the compiler, no special code is
required). And the special design of COS dispatcher allows it to be
x2-3 faster than the one of Dynace and x1.6 faster than the one of
Objective-C.
Now, all these remarks does not invalidate your other remark about
boxing / unboxing primitive types. It's true that it's more
complicated to implement abstractions like your Pixel class and it
will consume more memory (x3 more for your example in COS, unless you
write an Image class). So in principle, you will have to implement a
higher-level Image class to reach the same efficiency.
To conclude, there is a tradeoff in both approach, since the COS/
Objective-C/Dynace way do not allow efficient low-level abstraction
like your Pixel class, but they do allow (in particular COS) to design
powerful components quite hard (or impossible) to implement in C++.
It's up to the developer to choose the right tools.
a+, ld. |
|
|
| Back to top |
|
|
|
| Juha Nieminen... |
Posted: Tue Jul 14, 2009 10:42 pm |
|
|
|
Guest
|
Blake McBride wrote:
Quote: Look, you seem to be hostile to Dynace. Don't use it.
I'm not hostile to Dynace. I'm hostile to your arguments in your
webpage badmouthing C++ for false reasons.
Exactly what do you expect when you come to a C++ group and promote
your own C extension and in your webpage you basically say that "C++
sucks, C rules, and Dynace rules even more"? Your views about C vs. C++
may be shared among prejudiced C hackers, but they are not shared by me
(and many other C++ programmers, I'm sure).
Quote: All languages have trade offs. Dyance solves many
issues commonly known in the C++ world at the expense of, essentially,
causing all method calls to be virtual.
And, I assume, forcing each object to be allocated dynamically, making
the creation of objects slower and making them consume more memory.
Imagine you have something like this in C++:
class Pixel
{
unsigned char red, green, blue, alpha;
public:
// public methods here, none of which are virtual
};
Then you do something like this: std::vector<Pixel> image(10000000);
(and maybe initialize with some image data, or whatever).
In C++ that vector will consume about 40 megabytes of memory. How much
would the equivalent code in Dynace consume (using the same level of
abstraction, ie. no cheating by using a C struct as the Pixel type)?
Also, even with virtual methods, I don't see how you can have them as
fast as the ones in C++ given that, if I understood correctly, all
object pointers are completely opaque (as your webpage prominently
advertises, the entire class declaration is in the .c file rather than
in a header file, which would mean that object pointers must be
completely opaque, ie. the compiler does not see the class structure
when it makes a method call using that pointer).
In C++, since the compiler sees the entire class structure, making a
virtual function call is basically reading a function address from a
fixed offset in the virtual table, and jumping to that address. If,
however, the compiler would not see the class structure, it has no way
of knowing from the opaque pointer what this offset might be, without
doing more elaborate operations to resolve it. |
|
|
| Back to top |
|
|
|
| Flash Gordon... |
Posted: Tue Jul 14, 2009 11:57 pm |
|
|
|
Guest
|
Juha Nieminen wrote:
Quote: Blake McBride wrote:
<snip>
Quote: sucks, C rules, and Dynace rules even more"? Your views about C vs. C++
may be shared among prejudiced C hackers, but they are not shared by me
(and many other C++ programmers, I'm sure).
<snip>
Please take your prejudice against C programmers to an advocacy group
somewhere. I doubt that the attitudes and opinions of Blake are any more
representative of C programmers than they are of C++ programmers. In
fact, many of us who program in C program in many other languages as
well, so we are no more C programmers than we are Java, Perl, XSLT or
anything else programmers.
--
Flash Gordon |
|
|
| Back to top |
|
|
|
| Victor Bazarov... |
Posted: Wed Jul 15, 2009 12:31 am |
|
|
|
Guest
|
Flash Gordon wrote:
Quote: Juha Nieminen wrote:
Blake McBride wrote:
snip
sucks, C rules, and Dynace rules even more"? Your views about C vs. C++
may be shared among prejudiced C hackers, but they are not shared by me
(and many other C++ programmers, I'm sure).
snip
Please take your prejudice against C programmers
There is no prejudice against "C programmers" in Juha's comments.
Please don't confuse the expressions "C programmers" and "prejudiced C
hackers".
Quote: to an advocacy group
somewhere. I doubt that the attitudes and opinions of Blake are any more
representative of C programmers than they are of C++ programmers. In
fact, many of us who program in C program in many other languages as
well, so we are no more C programmers than we are Java, Perl, XSLT or
anything else programmers.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask |
|
|
| Back to top |
|
|
|
| ld... |
Posted: Wed Jul 15, 2009 7:25 pm |
|
|
|
Guest
|
On 15 juil, 21:04, Juha Nieminen <nos... at (no spam) thanks.invalid> wrote:
Quote: ld wrote:
You can simulate object-oriented programming in C to an extent, but
since the language has basically no support, it will inevitably be
rather "hacky" and complicated.
Wrong.
I have yet to see a clean solution.
Did you read the paper I mentioned?
http://cos.cvs.sourceforge.net/viewvc/cos/doc/cos_draft-dls09.pdf.gz
Quote: Do you _really_ know what is doable with C macros?
I'm pretty sure you cannot resolve the proper format string to use
with printf() to print something you got as a macro parameter
(especially if that something is eg. a struct instantiation). I'm also
pretty sure you cannot eg. resolve whether a parameter is of an integral
or a non-integral type.
But this not OOP.
So?
this thread is about OOP in/for C in the way of Dynace, not about C++
non-OOP features like generic (generative) programming. I have never
said that C macros can do the same as C++ template. My statement is
that they can do enough to implement clean _OOP_ in C.
a+, ld. |
|
|
| Back to top |
|
|
|
| Brian Wood... |
Posted: Wed Jul 15, 2009 7:40 pm |
|
|
|
Guest
|
On Jul 15, 11:58 am, Juha Nieminen <nos... at (no spam) thanks.invalid> wrote:
Quote: Brian Wood wrote:
Me too. And for about the same reason I like the Boost Intrusive
containers as they give the option of not having a data member
that is incremented/decremented every time elements are added or
removed.
As if one data member was that much of overhead...
Sure, but there is the run time aspect as well. If an
application adds a billion elements to a container and
then goes through them and eliminates all but 200,000
and you don't need to know the size of the container,
that's a lot of incrementing and decrementing that adds
nothing of value to the application. The point is that
if you don't need to know the size, having the option
to not have a member yields a slightly better application.
I use quite a few containers so as they say, "Every little
bit helps."
Brian Wood
Ebenezer Enterprises
www.webEbenezer.net |
|
|
| Back to top |
|
|
|
| Squeamizh... |
Posted: Wed Jul 15, 2009 8:04 pm |
|
|
|
Guest
|
On Jul 15, 12:25 pm, ld <Laurent.Den... at (no spam) gmail.com> wrote:
Quote: On 15 juil, 21:04, Juha Nieminen <nos... at (no spam) thanks.invalid> wrote:
ld wrote:
You can simulate object-oriented programming in C to an extent, but
since the language has basically no support, it will inevitably be
rather "hacky" and complicated.
Wrong.
I have yet to see a clean solution.
Did you read the paper I mentioned?
http://cos.cvs.sourceforge.net/viewvc/cos/doc/cos_draft-dls09.pdf.gz
Do you _really_ know what is doable with C macros?
I'm pretty sure you cannot resolve the proper format string to use
with printf() to print something you got as a macro parameter
(especially if that something is eg. a struct instantiation). I'm also
pretty sure you cannot eg. resolve whether a parameter is of an integral
or a non-integral type.
But this not OOP.
So?
this thread is about OOP in/for C in the way of Dynace, not about C++
non-OOP features like generic (generative) programming. I have never
said that C macros can do the same as C++ template. My statement is
that they can do enough to implement clean _OOP_ in C.
That was not your original statement, and you waste everyone's time by
being dishonest.
Here is the original context:
JUHA: There are many things doable with templates which are impossible
to do in C with precompiler macros.
YOU: Do you _really_ know what is doable with C macros? |
|
|
| Back to top |
|
|
|
| REH... |
Posted: Wed Jul 15, 2009 8:49 pm |
|
|
|
Guest
|
On Jul 15, 4:38 pm, Juha Nieminen <nos... at (no spam) thanks.invalid> wrote:
Quote: BGB / cr88192 wrote:
I say, the "pixel" class does not need to exist in the first place.
I don't want to sound rude, but it just sounds to me that you are
basing your design on the limitations of the programming language and
then rationalizing that it's "better" that way.
I disagree with your statement. A "pixel" is a concept, and in OOP a
class is precisely what is used to describe a concept. You usually want
to abstract away the concept of "pixel" (because you don't want to eg.
fix the amount of color channels, bits-per-pixel, color channel
ordering, and so on, and instead you usually want to use an abstract
"pixel" concept where those details are hidden so that the outside code
won't depend on any single representation). There's certainly no harm in
defining a "pixel" as a class (well, not in C++ at least).
Besides, the "pixel" class was just a simple example. I'm sure that
you can think of other similar examples where humongous amounts of small
objects are needed. Things like rational or complex numbers in some
math-heavy application comes to mind as another example.
In this case, I get his point. I've done DSP programming before, and
usually you have specialize libraries of highly-optimized vector math
routines that take advantage of the DSP's special architecture. This
routines usually only operate on arrays, and you almost always need to
speed boost that they give you. In my case, using the vector library
increase the number of signals we could concurrently process by a
factor of 12.
REH |
|
|
| Back to top |
|
|
|
| Brian Wood... |
Posted: Wed Jul 15, 2009 9:25 pm |
|
|
|
Guest
|
On Jul 15, 11:43 am, Juha Nieminen <nos... at (no spam) thanks.invalid> wrote:
Quote: Brian Wood wrote:
The part about each object having at least one pointer
pointing to it is not correct at least for the way I
use the Boost Intrusive containers. The objects stored
in the containers are deleted by taking their addresses.
You need *some* pointer to the object if you want to destroy it. If
you have dropped all pointers to it, then it's an orphan object which
you can't access anymore from anywhere (the only mechanism which can
still access it is a garbage collection engine).
I'm disagreeing with your statement that "each object
has at least one pointer pointing to it." Initially there
is a pointer pointing to the object, but then that pointer
is reused for another object. The objects are stored in
intrusive containers. So for the most part (except
initially) there aren't any pointers to the object around.
When you're ready to delete the object, you take the
address of it.
Quote: Even if you use an intrusive container, you are using pointers to the
objects, and they naturally take space.
Not pointers, but one pointer that points to each of the objects
for a little while.
Brian Wood
Ebenezer Enterprises
www.webEbenezer.net |
|
|
| Back to top |
|
|
|
| Brian Wood... |
Posted: Wed Jul 15, 2009 10:05 pm |
|
|
|
Guest
|
On Jul 15, 2:43 pm, Juha Nieminen <nos... at (no spam) thanks.invalid> wrote:
Quote: Brian Wood wrote:
I'm disagreeing with your statement that "each object
has at least one pointer pointing to it." Initially there
is a pointer pointing to the object, but then that pointer
is reused for another object. The objects are stored in
intrusive containers. So for the most part (except
initially) there aren't any pointers to the object around.
When you're ready to delete the object, you take the
address of it.
Exactly how do you take the address of a dynamically allocated object
you don't have a pointer to? Care to show some code?
This is non compiled code.
intrusive::list<myClass> lst;
myClass* ptr = new myClass(...);
lst.push_back(*ptr);
....
ptr = new myClass(...);
lst.push_back(*ptr);
....
intrusive::list<myClass>::iterator it = lst.begin();
intrusive::list<myClass>::iterator itend = lst.end();
for (; it != itend; ++it) {
delete &*it;
}
I'm not looking at a real example and just going by
memory, but that is close I think.
Quote: Rather obviously the intrusive container needs to store a pointer to
the object *somewhere*. It can't just drop the pointer and expect later
to be able to re-retrieve it by magic. That's just impossible.
I don't think it's possible to have something like
intrusive::list<myClass*>. That won't compile.
Quote: Even if you use an intrusive container, you are using pointers to the
objects, and they naturally take space.
Not pointers, but one pointer that points to each of the objects
for a little while.
As long as the object lives, at least one pointer must point to it. If
no pointer pointed to the object, the object becomes unretrievable and
thus has been leaked (except by some garbage collection mechanism).
The container can still give you access to the objects, but doesn't
have pointers to them.
Brian Wood
Ebenezer Enterprises
www.webEbenezer.net |
|
|
| Back to top |
|
|
|
| REH... |
Posted: Wed Jul 15, 2009 11:06 pm |
|
|
|
Guest
|
On Jul 15, 5:55 pm, Keith Thompson <ks... at (no spam) mib.org> wrote:
Quote: I'm not familiar with "intrusive containers", but if the object is
physically contained within the container (perhaps within an array),
the container wouldn't need to keep a pointer to it; it could
recompute the object's address at any time.
An intrusive container reduces copying by keeping the actual object
given to the container, as opposed to making a copy of the object
(i.e., owner of the object is given to the container). I believe
(though this just my assumption) that they are called intrusive
because the container requires that the object supply particular
members (e.g., such as next/previous pointers).
REH |
|
|
| Back to top |
|
|
|
| Ben Pfaff... |
Posted: Wed Jul 15, 2009 11:21 pm |
|
|
|
Guest
|
Juha Nieminen <nospam at (no spam) thanks.invalid> writes:
Quote: You can do surprising things with template metaprogramming (all at
compile time), such as linked lists (with many operations familiar from
lisp, such as getting the first element and the list tail, etc), binary
trees, resolving whether a given integer is prime or not...
I think you've put your finger on the problem with template
metaprogramming: people tend to do surprising things with it.
Programming should not be surprising.
--
Ben Pfaff
http://benpfaff.org |
|
|
| Back to top |
|
|
|
| Juha Nieminen... |
Posted: Wed Jul 15, 2009 11:24 pm |
|
|
|
Guest
|
BGB / cr88192 wrote:
Quote: but, there is another overlooked possibility:
a flat linear array of bytes...
as another has noted:
we can have an "image" class, not a "pixel" class...
Then you diminish the reusability of the "pixel" class for other
purposes than a 2D bitmap image. |
|
|
| Back to top |
|
|
|
| Juha Nieminen... |
Posted: Wed Jul 15, 2009 11:51 pm |
|
|
|
Guest
|
Brian Wood wrote:
Quote: Sure, but there is the run time aspect as well. If an
application adds a billion elements to a container and
then goes through them and eliminates all but 200,000
and you don't need to know the size of the container,
that's a lot of incrementing and decrementing that adds
nothing of value to the application. The point is that
if you don't need to know the size, having the option
to not have a member yields a slightly better application.
I use quite a few containers so as they say, "Every little
bit helps."
Have you actually tested it in practice whether that counter makes any
significant difference? There are much heavier operations involved in
creating and destroying objects dynamically than some individual counter
integral. |
|
|
| Back to top |
|
|
|
|
|
All times are GMT
The time now is Tue Dec 01, 2009 8:03 pm
|
|