Current News Archived News Search News Discussion Forum Old Forum Install Programs More Downloads... Troubleshooting Source Code Format Specs. Misc. Information Non-SF Stuff Links Small banner for links to this site: |
1 // SMem.cpp - Memory functions
2 //
3 // Converted from assembly to C++ by ShadowFlare.
4 // E-mail : blakflare@hotmail.com
5 // Webpage : http://sfsrealm.hopto.org/
6 // License information for this code is in license.txt
9 #include "SMem.h"
10 #include <stdlib.h>
12 LPVOID WINAPI SMemAlloc(DWORD dwSize)
13 {
14 LPVOID lpMemory = malloc(dwSize);
15 if (lpMemory) SMemZero(lpMemory,dwSize);
16 return lpMemory;
17 }
19 void WINAPI SMemFree(LPVOID lpvMemory)
20 {
21 if (lpvMemory) free(lpvMemory);
22 }
24 DWORD WINAPI SMemCopy(LPVOID lpDestination, LPCVOID lpSource, DWORD dwLength)
25 {
26 DWORD dwPrevLen = dwLength;
27 LPDWORD lpdwDestination = (LPDWORD)lpDestination,lpdwSource = (LPDWORD)lpSource;
28 LPBYTE lpbyDestination,lpbySource;
30 dwLength >>= 2;
32 while (dwLength--)
33 *lpdwDestination++ = *lpdwSource++;
35 lpbyDestination = (LPBYTE)lpdwDestination;
36 lpbySource = (LPBYTE)lpdwSource;
38 dwLength = dwPrevLen;
39 dwLength &= 3;
41 while (dwLength--)
42 *lpbyDestination++ = *lpbySource++;
44 return dwPrevLen;
45 }
47 void WINAPI SMemZero(LPVOID lpDestination, DWORD dwLength)
48 {
49 DWORD dwPrevLen = dwLength;
50 LPDWORD lpdwDestination = (LPDWORD)lpDestination;
51 LPBYTE lpbyDestination;
53 dwLength >>= 2;
55 while (dwLength--)
56 *lpdwDestination++ = 0;
58 lpbyDestination = (LPBYTE)lpdwDestination;
60 dwLength = dwPrevLen;
61 dwLength &= 3;
63 while (dwLength--)
64 *lpbyDestination++ = 0;
65 }
|