Skip to content

Instantly share code, notes, and snippets.

View drbobbeaty's full-sized avatar

Bob Beaty drbobbeaty

View GitHub Profile
@drbobbeaty
drbobbeaty / gist:634738
Created October 19, 2010 18:25
Simple ZeroMQ Receiver for Quotes
// System Headers
#include <iostream>
#include <stdio.h>
#include <string>
#include <stdint.h>
#include <sys/time.h>
// Third-Party Headers
#include <zmq.hpp>
@drbobbeaty
drbobbeaty / gist:635015
Created October 19, 2010 20:19
Simple ZeroMQ Transmitter of Messages
// System Headers
#include <iostream>
#include <stdio.h>
#include <string>
#include <stdint.h>
#include <sys/time.h>
// Third-Party Headers
#include <zmq.hpp>
@drbobbeaty
drbobbeaty / hexDump.cpp
Created November 30, 2010 21:41
Simple method to dump a ZeroMQ message to a std::string.
#include <string>
#include <strings.h>
#include <stdint.h>
std::string hexDump( zmq::message_t & aMessage ) {
// I'm going to build a hex/ascii dump like you've seen so many times before
std::string msg;
std::string ascii;
// get the pointer to the start of the message's payload - and it's size
char *buff = (char *)aMessage.data();
@drbobbeaty
drbobbeaty / heavySender.cpp
Created December 2, 2010 21:55
Simple ZMQ Transmitter Illustrating Memory Usage
/**
* On my CentOS 5 system this application sent the first 3000 messages
* with a running memory footprint less than 7 MB. In a few minutes, it
* leveled out at 18MB. Based on the sending rate, the maximum data rate
* out of this process should be less than 75kbps -- well below the
* ZMQ_RATE of 10Mbps. While there doesn't seem to be a long-term leak,
* the fact that this application does the first 3000 sends with a memory
* footprint far less than it's terminal value is concerning.
*
* If I change nothing other than the ZMQ_RATE value and change it to
@drbobbeaty
drbobbeaty / gist:794827
Created January 25, 2011 11:53
Simple SUB Connection Test
// System Headers
#include <iostream>
#include <stdio.h>
#include <string>
#include <stdint.h>
#include <sys/time.h>
// Third-Party Headers
#include <zmq.hpp>
@drbobbeaty
drbobbeaty / gist:821426
Created February 10, 2011 21:54
This is my mult-prod/sing-cons lockless FIFO template queue
/**
* LinkedFIFO.h - this file defines a multi-producer/single-consumer linked
* FIFO queue and is using the compare-and-swap to achieve
* the lock-free goal.
*/
#ifndef __LINKEDFIFO_H
#define __LINKEDFIFO_H
// System Headers
#include <stdint.h>
@drbobbeaty
drbobbeaty / gist:830383
Created February 16, 2011 22:16
This is my lockless Ring FIFO Queue
/**
* RingFIFO.h - this file defines a multi-producer/single-consumer circular
* FIFO queue and is using the compare-and-swap to achieve
* the lock-free goal. The size of this buffer is given as a
* power of 2 - so saying:
* RingFIFO<int, 10> a;
* makes a ring buffer of 2^10 = 1024 ints.
*/
#ifndef __RINGFIFO_H
#define __RINGFIFO_H
@drbobbeaty
drbobbeaty / gist:832520
Created February 17, 2011 19:57
Improved MP/SC lockless Ring FIFO Queue
/**
* RingFIFO.h - this file defines a multi-producer/single-consumer circular
* FIFO queue and is using the compare-and-swap to achieve
* the lock-free goal. The size of this buffer is given as a
* power of 2 - so saying:
* RingFIFO<int, 10> a;
* makes a ring buffer of 2^10 = 1024 ints.
*/
#ifndef __RINGFIFO_H
#define __RINGFIFO_H
@drbobbeaty
drbobbeaty / gist:853122
Created March 3, 2011 17:15
Erlang Ring Benchmark from Erlang book by J Armstrong (Chapter 8 Exercises)
-module(ring).
-export([start/0, test/2]).
%% make the state container for the ring node
-record(state, {next, origin, caller}).
%% standard entry point for a 1000 node, 500 cycle test
start() ->
test(1000, 500).
@drbobbeaty
drbobbeaty / gist:869313
Created March 14, 2011 15:28
C++ version of the Erlang Ring from Chapter 8 of Armstrong
/**
* ring.cpp - this is the C++ equivalent of the Armstrong Chapter 8
* exercise where you are supposed to make a ring of 'n'
* objects and have one fire another for a total of 'm' laps.
*/
// System Headers
#include <stdint.h>
#include <iostream>
#include <sys/time.h>