Skip to content

Instantly share code, notes, and snippets.

@newpolaris
newpolaris / display_memory.cpp
Created July 2, 2020 08:39
memmory-alloc-test
#include <Windows.h>
#include <Psapi.h>
void writeOut()
{
HANDLE process = GetCurrentProcess();
PROCESS_MEMORY_COUNTERS_EX pmc;
FILE* f = NULL;
fopen_s(&f, "qwert.txt", "a+");
MEMORYSTATUSEX statex;
@newpolaris
newpolaris / text_compress.link
Last active June 8, 2020 05:42
texture compression
@newpolaris
newpolaris / CommandBufferQueue.cpp
Last active May 10, 2020 22:18
CommandBufferQuque snipet from filament
#include <iostream>
#include <vector>
#include <mutex>
#include <condition_variable>
class CommandStream {
public:
void execute(void* buffer);
@newpolaris
newpolaris / Makefile
Created May 3, 2020 04:23
simple make file
# https://changkun.de/modern-cpp/en-us/01-intro/index.html
C = gcc
CXX = clang++
SOURCE_C = foo.c
OBJECTS_C = foo.o
SOURCE_CXX = 1.1.cpp
@newpolaris
newpolaris / shared_future.cpp
Created February 22, 2020 11:17
shared_future.cpp
#include <iostream>
#include <future>
#include <type_traits>
#include <queue>
#include <mutex>
using job_t = std::packaged_task<int(void)>;
std::queue<job_t> jobs;
std::mutex mutex;
std::condition_variable cond;
@newpolaris
newpolaris / MagicRingbuffer.cpp
Last active February 15, 2020 08:38
Magic ringbuffer
#include <iostream>
#include <cassert>
#include <sys/mman.h>
#include <unistd.h>
void* cbuffer_new(const size_t size)
{
char path[] = "/tmp/cb-XXXXXX";
int fd, status;
void* address;
@newpolaris
newpolaris / gray.cc
Created February 12, 2020 06:32 — forked from jiafulow/gray.cc
C++ Gray code
//
// Code from "Numerical Recipe in C (2nd edition)" by Press et al.
// Chapter 20.2 pg.896
//
#include <cstdint>
#include <iostream>
// Return the Gray code of n
uint64_t gray(uint64_t n)
@newpolaris
newpolaris / ...
Created February 11, 2020 10:01
...
#include <gtest/gtest.h>
#include <mutex>
#include <atomic>
#include <algorithm>
#include <bitset>
namespace pointermath {
template <typename P, typename T>
static inline P* add(P* a, T b) noexcept {
https://gitlab.unistra.fr/j.vanassche/arkanoid/blob/9bd3ac4d474fa2fd492c9624ecdcc4d1be13af96/Arkanoid/SDL2_OO/SDL2-2.0.8/src/render/metal/SDL_render_metal.m
/* macOS requires constants in a buffer to have a 256 byte alignment. */
#ifdef __MACOSX__
#define CONSTANT_ALIGN 256
#else
#define CONSTANT_ALIGN 4
#endif
@newpolaris
newpolaris / 222
Last active February 5, 2020 09:58
11
/*
Copyright (C) 2015 Apple Inc. All Rights Reserved.
See LICENSE.txt for this sample’s licensing information
Abstract:
Metal Renderer for Metal Basic 3D. Acts as the update and render delegate for the view controller and performs rendering. In MetalBasic3D, the renderer draws 2 cubes, whos color values change every update.
*/
#import "AAPLRenderer.h"
#import "AAPLViewController.h"