Sunday, April 10, 2011

Finally get back all 4GB memory

HP is so ridiculous to send me a 64-bit quad-core HP Pavilion s5235 but a 32-bit Windows 7. Only one thing troubles me, that only 3.25GB (4GB memory is installed) memory is usable. So I called HP customer service, but they cannot give me a 64-bit Windows due to some 64-bit hardware driver problems They also said that I am lucky, because on some devices only 2.99GB memory can be recognized.

Generally speaking, 3.25GB memory is significant for me. And I believed that this is a hardware limitation for a 32-bit operating system, until I read this article. Now I'd like to share you a very simple way to use 4GB memory on a 32-bit Windows 7.

  1. Disable your anti-virus program temporarily. 
  2. Download the software ReadyFor4GB from here or here 
  3. Apply the patch and reboot your system

It works perfect but you will see a "Test mode ..." watermark on the right bottom of every screen. Because the patch instructs you to add "testsigning on" to the startup script, which you cannot bypass. The correct thing you should do is:

  1. Download the software RemoveWatermark from here, here or here
  2. Apply the patch by pressing 'Y' and reboot your system

Now you can use full 4GB memory!

Sunday, December 19, 2010

Introducing Word Lens

Sunday, October 10, 2010

Use the magic number

Here is a very interesting article http://www.matrix67.com/data/InvSqrt.pdf

Thursday, April 23, 2009

Potential memory leaks by initializing a record (revised)

Currently I am involved in some D projects. Language D has nothing to do with Delphi. It has a lot of great features: Design by Contract, Templates, immutable, Array-Slicing, etc. My teammates give me a lot of advices on software design. One thing just inspired me. so I revised my old article "Potential memory leaks by initializing a record".

The main point is that FillChar() looks more like an abuse of initializing a record. I suggest declare a const record (eg. EmptyRecord) instead of using FillChar(). If you are an expert, you will NOT make such a mistake, but it is still worth to tell the rest Delphi developers.
 

Thursday, October 23, 2008

LIKE is not case insensitive?

I was stuck by understanding the following SQL query:


SELECT name
FROM my_table
WHERE name LIKE '%Jack%'

There is nothing special. It just tries to pick up all "names" of "my_table", those values contain the word "Jack" (case sensitive). However, "jack" is also in the result. I cannot believe my eyes.

I googled "LIKE case insensitive" and got the answer:
The problem is caused by the collation of the database. The default collation of my database is "latin1_swedish_ci". The trailing "_ci" stands for case insensitive. I changed it to "utf8_bin", the problem has been solved.

Here are some useful links:
http://forums.mysql.com/read.php?20,202839,202839
http://dev.mysql.com/doc/refman/5.0/en/pattern-matching.html
http://dev.mysql.com/doc/refman/5.0/en/charset-charsets.html

Wednesday, September 10, 2008

require_once()

If you used require_once(), you may have known one big issue of it: "If you give a relative path to the file you want to require, PHP will use the working directory as root, not the directory where this file is located." Your code won't have any problem, except the file to be required, requires some other files as well and unfortunately they are not in a same directory.

There are several solutions on the Internet.

  1. Put all PHP files into one folder. This works for tiny projects, but a flat folder structure is really ugly.
  2. Use a PHP framework, like Zend, CodeIgniter, CakePHP. They provide a certain function like $this->load() to find the correct path of these files and load them.
  3. If your code is not based on a framework, you can simply use
    "require_once(dirname(__FILE__).'/path_to_file')" instead of
    "require_once('path_to_file')". However this does not work on my xampp environment. My code hangs up when executing this line. (The problem seems not to be on the slash or backslash. Really no idea)

My Solution

Write a function to calculate the relative path from file directory to working directory. If you previously use "require_once('path_to_file')", now you write
"require_once(cp('path_to_file'))". It has been tested on Windows.

if (!function_exists('cp'))
{
function cp($f) // change_path
{
if (($wp = getcwd()) === ($fp = dirname(__FILE__))) { return $f; }
$wp = explode('\\', $wp);
$fp = array_merge(explode('\\', $fp), explode('/', $f));
for ($i = 0, $p = min(count($wp), count($fp)); $i < $p; $i++)
{
if ($wp[$i] === $fp[$i])
{
array_shift($wp);
array_shift($fp);
$i--; $p--;
continue;
}
break;
}
$p = ''; foreach ($wp as $k) { $p .= '../'; }
return $p.implode('/', $fp);
}
}

Saturday, August 9, 2008

Quick note on UnicodeString

Jan Goyvaerts has introduced some key information about Unicode in Delphi 2009.
http://www.micro-isv.asia/2008/08/get-ready-for-delphi-2009-and-unicode/

Marco Cantu has made a performance comparison between AnsiString and UnicodeString.
http://blog.marcocantu.com/blog/tiburon_unicode_video_5.html

Conclusion

According to the information, so much I have collected in the past a few months, I summarized them as the following points:
  1. Simple projects can be upgraded to Delphi 2009 without any modifications. Projects with heavy string operations or file operations could be compiled as well. But they should be tested completely before release.
  2. UnicodeString is based on the same concept as AnsiString. So it is very fast and efficient, although it is a little bit slower than AnsiString.
  3. In compare with WideString much less memory will be allocated for UnicodeString. If it is not necessary, you had better switch WideStrings to UnicodeStrings for a performance boost.

UPDATE 1: Here and here are detailed performance tests