Skip to main content

Posts

Showing posts from June, 2015

Learning Scratch (2)

My last blog entry, I briefly talk about what is Scratch. There are ``events'' and that is the trigger of the program. In this article, I would like to talk about one of my students who made a character animation program by Scratch. Scratch provides key events. When I push the right arrow key, then ``right arrow key push event'' is triggered. When that event happened, I add 10 to the x coordinate of the cat. This means, when the right arrow button pushed, the cat move to the right for 10 steps. If I add more programs like the up arrow moves the cat to upper direction, I can control the cat position by the arrow keys. This is a cat control program. Today, my student used a dragon. He wrote the same program with the cat. Then, the cat and the dragon move exactly the same way. Of course they should. A current computer is very fast, very precise, and very stupid. It does only what the developer wrote. My student asked me, how he can make the dragon faster. I answered, i...

Learning Scratch (1)

I teach Scratch [1] , a computer programming language, to 10 to 12 years old students from last year. Sometimes they show me an interesting creative idea. I would like to write one of them here. Before I explain what my students did, I will explain what is Scratch. First I will explain it in a conceptual way, then with an example. If someone can understand a conceptual explanation, he/she can apply the idea to many cases, but this is a bit difficult since their understanding must be deep. An explanation by example is rather easy to understand since it is shallow, that means you don't know it is still true in other cases. So there is a trade-off. Scratch is a computer language, but also a programming environment.  In the environment, the developer writes event driven programs to control many sprite [2] characters. You can think each sprite character an object. Each event invokes a program and each program runs in parallel. Maybe this explanation doesn't make sense for who...

Inter process communication by a shared memory

I made an experience for an inter process communication using a Unix shared memory on a host. I look up on the Internet, but I could not find a good example code. In the end, I found some explanation articles, some Stack overflow threads. (I might do something wrong when I search...) Some pages suggest to use shmem_open() and mmap(), that is the POSIX direction. I think I can believe the discussion, so I implemented it the following way. The basic idea is the following: A process creates an shared memory area using shm_open().  To identify the shared memory area between processes, we use an identifier string (e.g., ``identifier''). (On Linux environment, You can see via /dev/shmem, e.g., /dev/shmem/identifier .) All processes map that shared memory are to main memory using mmap(). When we succeeded mmap(), we obtained a shared memory pointer (shared_ptr). The processes can communicate via shared_ptr. When we finished to use the shared_ptr, remove the map using mu...