ruin

2011年10月14日

Disable Smart Window Arrangement on Windows 7

Filed under: Uncategorized — Tags: , — ハルキ @ 9:16 pm

Windows 7’s Stupid Desktop icon arrangement really troubles me.
The icons on Desktop always get arranged unexpectedly, it takes me a lot of time to find them,
thanks god there is a way to disable it.

1. Run regedit.exe
2. Set HKEY_CURRENT_USER\Control Panel\Desktop\WindowArrangementActive to 0.

2011年9月23日

A simple C++ thread template

Filed under: Programming — Tags: , , , — ハルキ @ 10:38 am

Unfortunately c++ member function can not be used as a thread function directly,
usually I use virtual function to solve this problem, but use template is a better solution.

続きを読む…

2011年7月22日

implement virtual function using c

Filed under: Programming — Tags: , , , — ハルキ @ 2:33 pm
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
/* base.h */
 
struct base;
struct base_vtable {
    const char *type;
    int (*foo) (struct base *);
    int (*bar) (struct base *, int val);
    void (*release) (struct base *);
};
 
struct base {
    struct base_vtable *vptr;
};
 
int base_foo (struct base *b) {
    return b->vptr->foo (b);
}
 
int base_bar (struct base *b, int val) {
    return b->vptr->bar (b, val);
}
 
void base_release (struct base *b) {
    b->vptr->release (b);
}
 
void base_init (struct base *b) {
    b->vptr->type = "BASE";
    b->vptr->foo = &base_foo;
    b->vptr->bar = &base_bar;
}
 
/* derive.h */
struct derive {
    struct base super;
    int m;
};
 
void *derive_init();
int derive_foo (struct derive *d);
int derive_bar (struct derive *d, int val);
void derive_release (struct derive *d);
 
/* derive.c */
 
int derive_foo (struct derive *d) {
    printf ("derive_foo: %d\n", d->m);
}
 
int derive_bar (struct derive *d, int val) {
    printf ("derive_bar: %d\n", val);
}
 
void derive_release (struct derive *d) {
    puts ("derive_release");
    free(d);
}
 
struct base_vtable derive_vtable = {
    .type = "DERIVE",
    .foo = (void*)derive_foo,
    .bar = (void*)derive_bar,
    .release = (void*)derive_release,
};
 
void *derive_init () {
    struct derive* d = (struct derive*)malloc (sizeof (struct derive));
    d->super.vptr = &derive_vtable;
    d->m = 4321;
    puts("derive_init");
    return d;
}
 
int main (int argc, char *argv[]) {
    struct base* b = derive_init ();
    base_foo(b);    
    base_bar(b, 1234);  
/*  printf("%s\n", b->vptr->type); */
    base_release(b);
    return 0;
}

2011年7月15日

c++ class memory model

Filed under: Uncategorized — Tags: , — ハルキ @ 10:21 pm

use g++ with -fdump-class-hierarchy option
you can dump the memory model of classes,
it is quite amazing, definitely helpful.

2011年5月30日

Self Discipline

Filed under: Life — Tags: — ハルキ @ 12:50 pm

I realized all kinds of failures in my life are due to the lack of self discipline and I want to improve it.

1. Self discipline is an ability and it can be exercised and improvable.
2. Exercises self discipline start with the small things we do in our daily life.
3. Do the most important thing first in the day and don’t delay.
4. Do anything good for us but we don’t want to do regularly, let it become a habit, then we don’t need to consume our will power to do it.

次ページへ »

14 queries. 0.228 seconds.   Powered by WordPress