⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tech.h

📁 Generating Fractals with SSE/SSE2 You probably have heard about fractals before. They are beautiful
💻 H
字号:
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <commctrl.h>
//#include <math.h>
#include "resource.h"
#include <limits.h>
#include <crtdbg.h>
#include <stdlib.h>
#include <ddraw.h>
#include <assert.h>

#ifndef _DEBUG
#pragma comment(linker, "/ENTRY:WinMain")
#pragma comment(linker,"/merge:.rdata=.text")
#endif
extern "C" int _fltused = 0;

#ifdef UNICODE
#define cmp2ch(s,a,b) (*(long*)(s) == \
	((unsigned short)(a) | (unsigned short)(b) << 16))
#define cmp4ch(s,a,b,c,d) (*(long*)(s) == \
	((unsigned short)(a) | (unsigned short)(b) << 16) && \
	*(long*)(s+2) == \
	((unsigned short)(c) | (unsigned short)(d) << 16))
#define set2ch(s,a,b) (*(long*)(s) = \
	((unsigned short)(a) | (unsigned short)(b) << 16));
#define set4ch(s,a,b,c,d) (*(long*)(s) = \
	((unsigned short)(a) | (unsigned short)(b) << 16), \
	*(long*)(s+2) = \
	((unsigned short)(c) | (unsigned short)(d) << 16));
#else
#define cmp2ch(s,a,b) (*(short*)(s) == \
	((unsigned char)(a) | (unsigned char)(b) << 8))
#define cmp4ch(s,a,b,c,d) (*(long*)(s) == \
	 ((unsigned char)(a) | (unsigned char)(b) << 8 |   \
     (unsigned char)(c) << 16 | (unsigned char)(d) << 24))
#define set2ch(s,a,b) (*(short*)(s) = \
	((unsigned char)(a) | (unsigned char)(b) << 8));
#define set4ch(s,a,b,c,d) (*(long*)(s) = \
	 ((unsigned char)(a) | (unsigned char)(b) << 8 |   \
     (unsigned char)(c) << 16 | (unsigned char)(d) << 24));
#endif

HANDLE heap;
SYSTEM_INFO si;
int inline ceil(const int i, const int power2) {
	return (i + power2 - 1) & -power2;
}
/*int inline floor(const int i, const int power2) {
	return i & -power2;
}*/
inline long* ceil(const void* i, const int power2) {
	return (long*)(((const int)i + power2 - 1) & -power2);
}
//#ifndef _DEBUG
size_t oldsize=0;
void __forceinline *malloc2(size_t n) { // Memory allocation and freeing
	//return HeapAlloc(heap, HEAP_NO_SERIALIZE, n);
	void* mem = VirtualAlloc(NULL, ceil(n, si.dwPageSize), MEM_COMMIT, PAGE_READWRITE);
	if(!mem) {
		MessageBox(0, TEXT("Out of memory"), TEXT("Fractals"), MB_ICONERROR);
		ExitProcess(1);
	}
	return mem;
}
#define malloc(a) malloc2(a)
// WARNING: that's a special case of the fast memory reallocator for this application only;
// the realloc() function won't work in other circumstances!
// Use commented out version with HeapAlloc/HeapRealloc/HeapFree instead.
void __forceinline *realloc2(void* p, size_t n) {
	if(n > oldsize) {
		VirtualFree(p, 0, MEM_RELEASE);
		oldsize = ceil(n, si.dwPageSize);
		void* mem = VirtualAlloc(NULL, oldsize, MEM_COMMIT, PAGE_READWRITE);
		if(!mem) {
			MessageBox(0, TEXT("Out of memory"), TEXT("Fractals"), MB_ICONERROR);
			ExitProcess(1);
		}
		return mem;
	}
	return p;
	//if (p == NULL) return malloc(n);
    //return HeapReAlloc(heap, HEAP_ZERO_MEMORY | HEAP_NO_SERIALIZE, p, n);
}
#define realloc(a, b) realloc2(a, b)
void __forceinline free2(void* p) {
	VirtualFree(p, 0, MEM_RELEASE);
    //if (p == NULL) return;
    //HeapFree(heap, HEAP_NO_SERIALIZE, p);
}
#define free(n) free2(n)
//#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -