Profile cover photo
Profile photo
Jon Stewart
273 followers
273 followers
About
Jon's posts

So, I've been thinking about using std::chrono and my existing poor-man's unit test framework to build a simple system for regression benchmarking C++ code, something akin to Python's timeit module (https://docs.python.org/3/library/timeit.html). It would run a given function several times, computing the average run time and variance. To have any value, it would need to persist these metrics per benchmark locally somewhere, and then compare present scores against the past, warning if a regression had occurred.

I'm envisioning something like this:
"""
SCOPE_BENCHMARK([]{
  vector<int> d;
  generate_n(back_inserter(d), 10000, rand());
  return [d]{ std::accumulate(d.begin(), d.end(), 0);
});
"""
where the initial lambda is setup code and the returned lambda is what gets benchmarked.

Questions? Comments? Smart remarks?

Heap Allocation Alignment

Let's say I'm writing a program in C/C++. I need a good-sized chunk of memory. In order to achieve sympathy with the underlying machine, I'd like for that chunk of memory to align with K pages of memory, where each page is presumably 4096 bytes in size.

The question I have, for +Christopher Smith et al, is: if I allocate an array of chars on the heap, how can I achieve alignment? My understanding is that when I write:

  char* ptr = new unsigned char[4096];

on a 64-bit system that typically 4104 bytes will be allocated by the heap, that the size of the block will be written into a word-size space at the beginning of the block, and then ptr will be set to the address following that word. So, that kind of blows.

While there may be no portable way to guarantee page alignment when asking the heap for memory, is there any sort of method that works well in practice? Do I just need to ask for 4088 bytes?

Post has attachment
Why hello there, Google Plus! I have a technical question regarding modern computer architecture.

Page 22 of Intel's HPC tuning guide (http://software.intel.com/sites/products/collateral/hpc/vtune/performance_analysis_guide.pdf) lists some useful latencies for cache and RAM accesses. What's interesting is that the listed L3 latency for a shared cache line is slightly more than the latency for local DRAM access (given NUMA banks) and, even stranger, is that a remote L3 cache hit (on a multi-cpu system) can be a few times slower than a remote DRAM access.

Oh what a wonderful new world, that has such timings in it!

So, the question is, why have L3 cache at all? To reduce pressure on the DRAM bus?

I put the SANS DFIR Google+ account in my circles, because, hey, I want to see their things in my stream. So far, so good.

They invite me to webinars and things. Okay, fine, no biggie.

What's goddamn ridiculous is that friggin' Google+ automatically adds these invites to my calendar without any acceptance from me. FUCKING WHAT THE FUCKING FUCK, FUCKING GOOGLE???? HOW DOES THIS SURVIVE A DAY IN THE PLEX, LET ALONE MONTHS IN THE WILD?!?!?!

I don't even see a setting where I can turn this off (although the G+ notification settings are fairly inscrutable). So, sorry, SANS DFIR, I'm unsubscribing. It's not your fault.

Post has attachment
Got bit by this backwards-incompatible change in C++11.

Here's the thing: I well understand the problems involved with having destructors throw willy-nilly. But, RAII is a great idiom: I want to do things at both ends of an object's life and the stack expresses this so conveniently. If throwing can never happen, even under safe conditions, then we're only permitted to do trivial things in a destructor. Do not like.

Is there a variable integer encoding that lexicographically preserves the ordering of the integer values?

Is there a good STL-ish C++ radix tree implementation out there?

A web design/architecture question for the lazyweb at large (cough +Gavin Doughtie *cough*):

I want to create a canonical real-time chat system on the web, in a RESTful, web-2.0ish manner. That is, I want to open up a page in my browser and start typing. My input is sent up to the server, changing the representation of the resource. Other browsers that are open on the same page receive updates automatically. How do I do this?

To the greatest extent possible, I want the server to be pretty dumb, just accepting inputs and then broadcasting state changes to clients, via JSON. Preferably, the server would be built with Jetty & Jersey, but if there's no way to get that to work, I'd consider other stacks.

But my question more is, how is this done from the JavaScript client-side? What do things look like on the wire? Are there JavaScript libraries (e.g. jQuery) that help with this? How does this work with REST?

Back in the day, I remember the words "comet" and "long-poll", but I don't really know what those mean, nor do I know whether those are the best ways to achieve this. Links to resources/tutorials appreciated, or even just terms to google. TIA.

Ok, LA C++ people, is it possible to do this?

template <class T, ...other stuff...>
T* safeCreate(...other stuff...) {
  try {
    return new T{other stuff}; // i.e., another stuff is brace-initialization
  }
  catch (...) {
    return nullptr;
  }
}

...

struct Foo {
  std::string S;
  int I;
}

auto fooPtr = safeCreate<Foo>({"yo", 3});

I know it it possible to get a handle on an initializer list, but is it possible to get a handle on the brace-initializer here and construct an arbitrary T off of it?

Not yet perfect but...


"Hello, void*, my old friend,
I've come to reinterpret_cast<> you again,
because destructors softly leaking,
left cyclic shared_ptr<>s still sneaking
and the wrong objects planted on the heap,
caused a beep.
It is the sound... of segfaults.
Wait while more posts are being loaded