Andy's insights

Opinions, thoughts, archivements

Sun, 30 Apr 2006

Memory Allocation

Ever wondered how memory allocation works? How to get informations and more. While searching on web for function to get the current memory size from within a process I’ve found this good article: Advanced Memory Allocation

And there is a really good article in c’t 9/2006 s. 186 about heap overflows.

posted at: 00:10 | path: /development | permanent link to this entry

Wed, 12 Apr 2006

D-Link harms NTP

Fine, D-Link managed to hardcode Stratum 1 NTP Server into their firmware. This stupidity leads to massive problems on those servers and immense costs for their carrier.

Read this open letter for full informations:

posted at: 23:07 | path: /net | permanent link to this entry

LS colors

If you ever typed ls into your black console, you may found it annoying that the directories where in dark blue color. This is hardly readable.

Here a short receipt how to change that:

  1. save current settings into a file: cd; dircolor -p > .colorsrc
  2. Edit your settings and change the line starting with ‘’‘DIR’‘’ DIR 01;34 into something more readable DIR 01;37;01
  3. add the following line to your ~/.bashrc if not alreay present: eval 'dircolor -b $HOME/.colorsrc'
  4. Log in or source your .bashrc and check the output of ls

posted at: 16:19 | path: /unix | permanent link to this entry

Singleton and Borg Design Pattern

The Singleton Design Pattern is quite popular.

As usual Python provides an easy and even better solution for most situations the Singleton seems appropriate. But first look at our options:

The classic Singleton pattern implemented in Python looks like this:

class Singleton(object):
    def __new__(cls, *p, **k):
        if not '_the_instance' in cls.__dict__:
            cls._the_instance = object.__new__(cls)
        return cls._the_instance

The Borg Design Pattern Borg Design Pattern shares just one state. I’ve found it at ASPN (Alex Martelli).

The main idea is to just share the state by replacing the default instance dictionary with a shared one:

class Borg(object):
    _state = {}
    def __new__(cls, *p, **k):
        self = object.__new__(cls, *p, **k)
        self.__dict__ = cls._state
        return self

The best solution I found is to just use the Python mechanics: A Module is a singleton, why not just use it?

class _SingleInstance(object):
    def __init__(self): = 23
SingleInstance = _SingleInstance
del _SingleInstance

A good discussion about those pattern (and some others) can be found here:

The Borg design pattern can be found at ASPN:

posted at: 13:05 | path: /python | permanent link to this entry