Category Archives: Uncategorized

Selecting Kth

Not an oracle related post. Life is stange, full of unexpectable scenerios. I think it wont be easy to make posts about oracle from now on. The below code is an algorithim comparision for finding th Nth element of a given list.

A formatter for WordPress ver1

It is very hard for me to publish code in my blog. unidentification, lock of colors etc..
http://rapidshare.com/files/12000281/codeFormatter.zip.html
This is a simple program that formates your files to publish on wordpress.
usage is:
ert@SEMERKAND:~/jdevhome/mywork/codeFormatter/Client/classes/client$ java -classpath .. client.Main in.tex out.tex 4
java.lang.Exception: no valid #CODE# found
at client.BlockHandler.process(BlockHandler.java:79)
[...]

Pragma pack over structures.

I have been working on my friends post
here is my test case:
————————————————————————————————————————–

ert@SEMERKAND:~$ cat dnm.cpp
#include <iostream>
union manken_u {
        char    ch;
        int     integer;
        double  db;
};
#pragma pack(2)
struct manken_s_p {
        char    ch;
        int     integer;
        double  db;
};
#pragma pack()
struct manken_s {
        char    ch;
        int     integer;
        double  db;
};
#define sub(x,y) (int)(x)-(int)(y)
int main()
{
        std::cout
                << ”size of union: ” << sizeof(union manken_u) << std::endl
                << ”size of struct: ” << sizeof(struct manken_s) << std::endl
                << ”size of packed struct: ” << sizeof(struct manken_s_p) << std::endl
                << ”size of char+int+double: ” << sizeof(char)+sizeof(int)+sizeof(double) << std::endl;
        manken_s my_struct;
        char* base = &my_struct.ch;
        std::cout
                << ”offset of char ” << sub(base,&my_struct.ch) << std::endl
                << ”offset of int ” << sub(base,&my_struct.integer) << std::endl
                << ”offset of db ” << sub(base,&my_struct.db) << std::endl;
        std::cout << ” pack is 2 ” << std::endl;
        manken_s_p my_struct_p;
        base = &my_struct_p.ch;
        std::cout
                << ”offset of char ” << sub(base,&my_struct_p.ch) << std::endl
                << ”offset of int ” << sub(base,&my_struct_p.integer) << std::endl
                << ”offset of db ” << sub(base,&my_struct_p.db) << std::endl;
        return 0;
}
ert@SEMERKAND:~$ g++ dnm.cpp
ert@SEMERKAND:~$ ./a.out
size of union: 8
size of struct: 16
size of packed struct: 14
size of char+int+double: 13
offset of char 0
offset of int -4
offset of db -8
 pack is 2
offset of char 0
offset of int -2
offset of db -6

————————————————————————————————————————–
So, what is the moral of the story:
#pragma pack is a directive for compiler to determine the size of atomic unit for storing nonprimitive data types (struct for example) on memory.
If you set it to 2, chars in a struct will have a size [...]

Migration

diriksoy.blogspot.com is dead. Heil erturkdiriksoy.wordpress.com