Skip to content

Instantly share code, notes, and snippets.

@engie
engie / shared_ptr_pooling.cpp
Created September 25, 2013 12:17
Notes on pooling shared ptr's
//Storing shared pointers in boost pool allocators
//tl;dr It just works (tm)
//
//* If a lot of smallish objects are being allocated & freed a pool allocator
//can speed things up by specialising in allocating exactly that size of
//object.
//
//* If pointer lifetimes need to be managed with reference counting,
//std::shared_ptr can wrap an object to provide safe reference counting.
//
@engie
engie / demo.cpp
Created July 14, 2013 14:06
An example of the Escalator project at work.
std::vector<int> a = { 3, 1, 4, 4, 2 };
std::vector<int> res6 = lift(a)
.zipWithIndex()
.filter( []( const std::pair<int, size_t>& v ) { return v.second > 0; } )
.map( []( const std::pair<int, size_t>& v ) { return v.first; } )
.toVec();
BOOST_CHECK_EQUAL( res6.size(), 4 );
CHECK_SAME_ELEMENTS( res6, std::vector<int> { 1, 4, 4, 2 } );
@engie
engie / after.scala
Created June 29, 2013 17:48
Scala auto-formatting going wrong.
trait FrontendRoutes extends ScalatraServlet with ScalateSupport {
val db: Database
get("/") {
contentType="text/html"
ssp("/index")
}
get("/matches") {
db withSession {
val q3 = for {
@engie
engie / LocalServer.scala
Created June 29, 2013 16:04
Unable to load resources when running scalatra servlet from local jetty instance.
import org.eclipse.jetty.server.Server
import org.eclipse.jetty.servlet.{DefaultServlet, ServletContextHandler}
import org.eclipse.jetty.webapp.WebAppContext
import org.scalatra.servlet.ScalatraListener
object JettyLauncher { // this is my entry object as specified in sbt project definition
def main(args: Array[String]) {
val port = if(System.getenv("PORT") != null) System.getenv("PORT").toInt else 8080
val server = new Server(port)
@engie
engie / gist:5161057
Last active December 14, 2015 22:48
test
This is also a test.
@engie
engie / unique_ptr_1.cpp
Created August 25, 2012 18:09
Use std::move to abandon ownership
#include <memory>
class A
{
public:
A( std::unique_ptr< int > v ) : m_v( std::move(v) ) {}
std::unique_ptr< int > m_v;
};
@engie
engie / gist:3468672
Created August 25, 2012 18:07
Compiler output compiling unique_ptr_fail1.cpp
$ g++ -std=c++11 -g -fPIC ptr.cpp -o ptr
ptr.cpp: In constructor ‘A::A(std::unique_ptr<int>)’:
ptr.cpp:6:44: error: use of deleted function ‘std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&) [with _Tp = int; _Dp = std::default_delete<int>]’
In file included from /usr/lib/gcc/x86_64-redhat-linux/4.7.0/../../../../include/c++/4.7.0/memory:86:0,
from ptr.cpp:1:
/usr/lib/gcc/x86_64-redhat-linux/4.7.0/../../../../include/c++/4.7.0/bits/unique_ptr.h:256:7: error: declared here
ptr.cpp: In function ‘int main(int, char**)’:
ptr.cpp:14:12: error: use of deleted function ‘std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&) [with _Tp = int; _Dp = std::default_delete<int>]’
In file included from /usr/lib/gcc/x86_64-redhat-linux/4.7.0/../../../../include/c++/4.7.0/memory:86:0,
from ptr.cpp:1:
@engie
engie / unique_ptr_fail1.cpp
Created August 25, 2012 18:07
Trying to copy a unique_ptr
#include <memory>
class A
{
public:
A( std::unique_ptr< int > v ) : m_v( v ) {}
std::unique_ptr< int > m_v;
};
@engie
engie / gist:2439378
Created April 21, 2012 20:09
Unrolled hand-crafted SSE matrix & vector product
const double* b_p = &(B.data()[0]);
double* w_p = &(W.data()[0]);
typedef double v2df __attribute__ ((vector_size (16)));
for( uint32 i = 0; i < rows; i++ ) //For each row
{
double* w_p_row = w_p;
double dp = 0;
/* Loop over 400 elements
@engie
engie / gist:2439337
Created April 21, 2012 19:59
Hand written SSE matrix * vector product
const double* b_p = &(B.data()[0]);
double* w_p = &(W.data()[0]);
for( uint32 i = 0; i < rows; i++ ) //For each row
{
double* w_p_row = w_p;
double dp = 0;
/* Loop over 400 elements
* Sum into sum