Couple of things could be happening.
1) Alignments are off, aligning of data really really matters when dealing with executable code. 2) For Windows only. Don't forget to call FlushInstructionCache. Before executing. https://msdn.microsoft.com/en-us/library/windows/desktop/ms679350(v=vs.85).aspx 3) Don't use new to get your executable memory, nope nope nope. Use things like VirtualAlloc as malloc doesn't work right see the first point.
