RAM Disk: A Very Interesting Idea…

Ξ June 29th, 2010 | → 0 Comments |
Tools |, , , |

Simply run:

$ mkfs -q /dev/ram1 8192   # 8192 = 8MB disk capacity
$ mkdir -p /mnt/ramcache
$ mount /dev/ram1 /mnt/ramcache
$ df -H | grep ramcache

to mount your own mini ramdisk.

For more details, here and here are some references I found on the subject.

You might ask yourself “Why does this guy needs a ramdisk?… What a geek!”, and wouldn’t mind. It was kind of a epiphany, when I remembered to use a ramdisk to run a “‘Lack of space’ Test Case” on the application I’m building right now.
After running the application, I just had to copy a mp3 album to occupy the remaining disk space… et voilá, welcome the expected “error message”. No, not a SIGSEGV, a real error dialog!…

 

Redirecting your intents

Ξ June 27th, 2010 | → 0 Comments |
Tools |, , |

command > filename

redirects the stdout from ‘command’ to a file called ‘filename’. The file shall be created if not present, or otherwise overwritten.

> filename
: > filename

are a special case of redirection, creating a zero-lenght file. The ‘:’ is a dummy placeholder that generates no content - usually used when the first form is not allowed by the shell.

command >> filename

also redirects the stdout to file, but the content is appended to file in the file already exists.

note: pre-pending 1, 2 or & will redirect stdout, stderr or both , according to the redirection ‘operator’ (>, >>).

 

A useful shortcut…

Ξ June 24th, 2010 | → 0 Comments |
Humor |, , |

Shift + Num Lock… whenever your numpad stops working on your ubuntu machine!

 

No more, no less… just perfect!

Ξ June 24th, 2010 | → 0 Comments |
Abstract |, , |

No more, no less… just perfect!
Time to rest.

 

Home, Sick, Alone…

Ξ June 4th, 2010 | → 0 Comments |
Music, Uncategorized |, , |

I might be home alone, taking care of this cold and the running nose, but found this on the internet and had to share.

 

More Pragmatic

Ξ May 7th, 2010 | → 0 Comments |
Uncategorized |, , , |

Andrew Hunt is becoming one of my favorite authors. The first book I read from Andy was “The Pragmatic Programmer“, which is a book full of insights on the life philosophy to become an expert programmer. Now I got my hands in “Pragmatic Thinking & Learning - Refactor Your Wetware” and it is another excellent book. This book is not only for software developers, it is intended for a wider audience and provides lots of tips to improve the way you think - it certainly made me think about the way I put by “mind” into the job.
I strongly recommend it…

 

On the radio…

Ξ April 18th, 2010 | → 0 Comments |
Music |, , , |

 

Yes, it’s true…

Ξ April 18th, 2010 | → 0 Comments |
Life |, , |

 

Factory

Ξ March 28th, 2010 | → 0 Comments |
Programming |, , , , , , |


 

My goal was to read an XML file containing a list of class names, and then instanciate the classes according to that list by caling a simple function inside a for loop.
The Abstract Factory is a very interesting design pattern that provides an encapsulation mechanism to the creation of families of objects. Combining this with the Factory Method it is possible build a factory that, after ‘generator method’ being registered, enables a simple mapping between a string object and an object.

The example shows an abstract Product which implements a given interface. There are two concrete products that derive from the base definition: a BigProduct and a SmallProduct. Then we have the Factory<T> that will be the production line for objects of type T. In the example, with T = Product, we have Factory<Product> that allows to call registration and creation methods, respectivelly:

template <class P>
void Factory<P>::registerProduct(const std::string& key, const Generator& generator)

template <class P>
P* Factory<P>::newProduct(const std::string& key)

The trick is that during registration you must provide the Generator function (also known as Factory Method) that will be used as building method by the factory. In this implementation, the Generator
is defined by the Factory itself but it could be defined anywhere as long as it returns a pointer to an abstract product. The implemented generation is based on default construction:

template <class P> template <class DP> // where P is Product and DP any kind of Derived Product
P* Factory<P>::generate()
{
return new DP();
}

In practice, using the factory is quite simple…

int main (void)
{
typedef Factory<Product> GenericFactory; // Simplifying the factory type…

GenericFactory factory;

// Register products and ‘generation’ methods…
factory.registerProduct(”BigProduct”, GenericFactory::generate<BigProduct>);
factory.registerProduct(”SmallProduct”, GenericFactory::generate<SmallProduct>);

// Calling for product creation
// NOTE: The use of auto pointer ensures that newly allocated object
//       is automatically destroyed as the end of scope
std::auto_ptr<Product> bp(factory.newProduct(”BigProduct”));
std::auto_ptr<Product> sp(factory.newProduct(”SmallProduct”));

bp->doFeature();
sp->doFeature();

return 0;
}

There is one very interesting evolution of this design that I’ve done, to enable runtime class registration. I’ll post on that the next time.



 

Surfin’ Bird

Ξ February 24th, 2010 | → 0 Comments |
Fun |, , , |

I was watching this on TV! Come on… this is ‘quality’ TV.

 

Previous Entries

On the nightstand...


    The Art of Agile Development


    Beautiful Architecture


    Modern C++ Design


    Large Scale C++ Software Design

Personal

Friends


Interesting


Shared Readings