Allegro.cc - Online Community

Allegro.cc Forums » Off-Topic Ordeals » Reasons to like or hate Java, C# and C++

This thread is locked; no one can reply to it. rss feed Print
 1   2   3   4 
Reasons to like or hate Java, C# and C++
Matthew Leverton
Supreme Loser
January 1999
avatar

Quote:

If it's anything like Java, you would make it a Java class, with a destructor that frees the underlying memory.

Yes, but then it's not quite as simple as what was originally shown. ;) Something like that probably works well with a language that is "compiled" like Java or C#, but for PHP it would add more overhead:

1<?php
2class Bitmap
3{
4 private $bmp;
5 public function __construct($w, $h, $cd = NULL)
6 {
7 if ($cd !== NULL)
8 $this->bmp = create_bitmap_ex($cd, $w, $h);
9 else
10 $this->bmp = create_bitmap($w, $h);
11 }
12 
13 public function __destruct($w, $h)
14 {
15 destroy_bitmap($this->bmp);
16 }
17}
18?>

You could take that same approach with PHP, but it's possible to do the same in the binding library and have it compiled to C. (This seems to be a big difference between PHP and Ruby... PHP has a lot of C modules, whereas Ruby modules are mostly written in Ruby.)

Quote:

I'm not php expert, but wouldn't you do something like this?

function allegro_init()
{
   global $screen;
   // ...
   $screen = get_allegro_var('screen');
   // ...
}

allegro_init() is a C module function, not a PHP function. However, I could probably do this:

PHP_FUNCTION(set_gfx_mode)
{
  long card, w, h, v_w = 0, v_h = 0;
  int rv;

  if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll|ll", &card, &w, &h, &v_w, &v_h) == FAILURE) RETURN_NULL();

  rv = set_gfx_mode(card, w, h, v_w, v_h);
// set the $GLOBALS['screen'] to screen

  RETURN_LONG(rv);
}

That works fine for 'screen', because it won't change. But I'm not sure if dynamic values like key[] can be mapped to a variable without requiring a poll() function to update it.

Marcello
Member #1,860
January 2002
avatar

That looks pretty painful ML, may I ask why you're bothering making a PHP wrapper? The graphics portion is pretty crude to do image manip since it's so simplistic.

Marcello

Matthew Leverton
Supreme Loser
January 1999
avatar

Quote:

may I ask why you're bothering making a PHP wrapper? The graphics portion is pretty crude to do image manip since it's so simplistic.

Just because I can... The majority of it is just a lot of copy and paste. I could have probably written a PHP script that automatically generated the code for almost every function.

Goalie Ca
Member #2,579
July 2002
avatar

Quote:

If it's anything like Java, you would make it a Java class, with a destructor that frees the underlying memory.

C# has what's called an IDispoable interface. A class that implements that interface is to be used to wrap things that manage resources. The problem with java is the opposite of c++. In c++ memory can leak while resources are taken care of automatically in the destructor when the object goes out of scope (assuming you don't use new and delete and use raii properly). In java you have to explicitly release ALL resources. While finalize may "automagically" release it, no one really knows when the GC will collect. It is not deterministic behaviour.

In c# you have the "disposable" concept. Basically they have a Dispose() method which is to be used to release resources. You can also have destructors. A using block in C# is basically a try{ }finally{ } block. The unsafe keyword means that you will manage the memory yourself. It IS needed when dealing with any useful C/C++ dll.

-------------
Bah weep granah weep nini bong!

CGamesPlay
Member #2,559
July 2002
avatar

Quote:

The unsafe keyword means that you will manage the memory yourself.

Well, mostly true, but this is a very crude definition of the keyword.

Quote:

It IS needed when dealing with any useful C/C++ dll.

It is only needed when you will need to work with pointers.

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

Goalie Ca
Member #2,579
July 2002
avatar

Quote:

Quote:
It IS needed when dealing with any useful C/C++ dll.

It is only needed when you will need to work with pointers

L0l. I'm glad you understand :D

-------------
Bah weep granah weep nini bong!

Archon
Member #4,195
January 2004
avatar

I managed to get GLFW working for Mono and Windows -- I think that Tao would be ready for use if the problems I told CGamesPlay would be solved...

Now CGames is taking ages to respond to emails!

[edit]
OK. No more problems with GLFW as far as I know... Though I'm still waiting for CGamesPlaysByHimself! >:(

 1   2   3   4 


Go to: