Friday, August 14, 2009

Joe's Chinese setup tips in Ubuntu

It is always good to meet fellow Ubuntu enthusiasts who are passionate about sharing information, experiences and knowledge.

Joe has written a few useful posts on setting up your Ubuntu system for Chinese. It also has good information on using Chinese input methods and fonts in OpenOffice.

Be sure to check it out if interested: Pinyin Joe's Ubuntu Linux Chinese setup

Monday, August 10, 2009

virtual memory and The Thing King

Knowing how Virtual Memory works is very useful in programming. Jeff Berryman's explanation from 1972 of the basics is just too useful to get started.

The Thing King and the Paging Game

Note: This note is a formal non-working paper of the Project MAC Computer Systems Research Division. It should be reproduced and distributed wherever levity is lacking, and may be referenced at your own risk in other publications.

Rules
1.Each player gets several million things.
2.Things are kept in crates that hold 4096 things each. Things in the same crate are called crate-mates.
3.Crates are stored either in the workshop or the warehouses. The workshop is almost always too small to hold all the crates.
4.There is only one workshop but there may be several warehouses. Everybody shares them.
5.Each thing has its own thing number.
6.What you do with a thing is to zark it. Everybody takes turns zarking.
7.You can only zark your things, not anybody else’s.
8.Things can only be zarked when they are in the workshop.
9.Only the Thing King knows whether a thing is in the workshop or in a warehouse.
10.The longer a thing goes without being zarked, the grubbier it is said to become.
11.The way you get things is to ask the Thing King. He only gives out things by the crateful. This is to keep the royal overhead down.
12.The way you zark a thing is to give its thing number. If you give the number of a thing that happens to be in a workshop it gets zarked right away. If it is in a warehouse, the Thing King packs the crate containing your thing back into the workshop. If there is no room in the workshop, he first finds the grubbiest crate in the workshop, whether it be yours or somebody else’s, and packs it off with all its crate-mates to a warehouse. In its place he puts the crate containing your thing. Your thing then gets zarked and you never know that it wasn’t in the workshop all along.
13.Each player’s stock of things have the same numbers as everybody else’s. The Thing King always knows who owns what thing and whose turn it is, so you can’t ever accidentally zark somebody else’s thing even if it has the same thing number as one of yours.
Notes
1.Traditionally, the Thing King sits at a large, segmented table and is attended to by pages (the so-called “table pages”) whose job it is to help the king remember where all the things are and who they belong to.
2.One consequence of Rule 13 is that everybody’s thing numbers will be similar from game to game, regardless of the number of players.
3.The Thing King has a few things of his own, some of which move back and forth between workshop and warehouse just like anybody else’s, but some of which are just too heavy to move out of the workshop.
4.With the given set of rules, oft-zarked things tend to get kept mostly in the workshop while little-zarked things stay mostly in a warehouse. This is efficient stock control.

Thursday, August 6, 2009

const pointer and pointer to a const

Here is a good question; What's the different between:
a) const char* c;
b) char* const c;

Answer:
A pointer is itself a variable which holds a memory address of another variable - it can be used as a "handle" to the variable whose address it holds.

a) This is a changeable handle/pointer to a const variable.
b) This is a const handle/pointer to a changeable variable.

This example might explain better:
#include 

int main()
{
int for_a = 100;
int for_b = 200;
int for_test = 300;

const int* a = &for_a;
int* const b = &for_b;

a++; // allowed
a--;
// *a = for_test; // not allowed: "assignment of read-only location"

// b++; // not allowed: "increment of read-only variable"
*b = for_test; // allowed

printf("Value of *a = %d, value of *b = %d \n", *a, *b);

return 1;
}


Irrelevant, but then 'const char* const c;' would mean a non-changeable pointer to a non-changeable variable.

Wednesday, August 5, 2009

what does segmentation fault mean?


Probably the best explanation of program memory I have seen is this article:
Anatomy of a Program Memory


Once you understand the program memory, you get a better idea what causes a "segmentation fault:

In summary, the major reasons for a segmentation fault are:

a) Trying to read from or write to addresses in kernel space of your program memory.
b) Trying to feed to push to the stack more data that it can fit.
c) Trying to write to the text segment of the process memory (text segment is where the binary image of the process is stored).
d) Trying to access unallocated memory.
When you ask for memory from the OS, the kernel creates an entry for you in the VMA - Virtual Memory Area. If you try to access a address in the memory and not suitable VMA exists for it, your program is going to have the segmentation fault.

extern/static in function declaration

I have never really paid attention to the 'extern' keyword in a function declaration, so here is my understanding of this.

In C:

In the simplest form, the 'extern' keyword changes the linkage so that the resolving is deferred to the linker. It is assumed that the function is defined/available somewhere else.

Whereas a 'static' keyword when declaring a function, it makes the function local to that file.

I suppose if you don't use the extern/static keyword when declaring the function, it defaults to extern.

static c variables are of course different than non-static variables.

In C++:

'static' functions in C++ have a very different usage. A static member function of a class is generally called without having to instantiate an object of the class. This is same for the static member variables of the class as well.

The static functions do have their limitations:

  • A static member function can access only static member data, static member functions and data and functions outside the class.
  • A static member function cannot be declared virtual, whereas a non-static member functions can be declared as virtual.
  • A static member function cannot have access to the 'this' pointer of the class.

wubi and update to new release

I have been recommending Wubi to a lot of folks as a simple way to switch to using Ubuntu without having to worry about partitioning, etc. Wikipedia has a pretty good write-up on Wubi.

The problem, as I had expected, is that upgrading to a new release when available comes with a host of problems.

This discussion thread talk about the problem. It is fairly recent, so I don't think there is a solution for this yet. Does anybody have some different information?

Tuesday, August 4, 2009

which version?

I keep having to look up which version of the distribution I am running and like every thing Linux, every distribution has decided to use it's own way.

For Ubuntu:
# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=8.04
DISTRIB_CODENAME=hardy
DISTRIB_DESCRIPTION="Ubuntu 8.04.3 LTS"


For RedHat/Fedora:

#cat /etc/redhat-release


For SUSE:
$ cat /etc/SuSE-release
openSUSE 11.1 (i586)
VERSION = 11.1