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




CommitLineData
3e09a0ee 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
7
8
9#include "SMem.h"
5d764a6b 10#include <stdlib.h>
3e09a0ee 11
12LPVOID WINAPI SMemAlloc(DWORD dwSize)
13{
14 LPVOID lpMemory = malloc(dwSize);
15 if (lpMemory) SMemZero(lpMemory,dwSize);
16 return lpMemory;
17}
18
19void WINAPI SMemFree(LPVOID lpvMemory)
20{
21 if (lpvMemory) free(lpvMemory);
22}
23
24DWORD 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;
29
30 dwLength >>= 2;
31
32 while (dwLength--)
33 *lpdwDestination++ = *lpdwSource++;
34
35 lpbyDestination = (LPBYTE)lpdwDestination;
36 lpbySource = (LPBYTE)lpdwSource;
37
38 dwLength = dwPrevLen;
39 dwLength &= 3;
40
41 while (dwLength--)
42 *lpbyDestination++ = *lpbySource++;
43
44 return dwPrevLen;
45}
46
47void WINAPI SMemZero(LPVOID lpDestination, DWORD dwLength)
48{
49 DWORD dwPrevLen = dwLength;
50 LPDWORD lpdwDestination = (LPDWORD)lpDestination;
51 LPBYTE lpbyDestination;
52
53 dwLength >>= 2;
54
55 while (dwLength--)
56 *lpdwDestination++ = 0;
57
58 lpbyDestination = (LPBYTE)lpdwDestination;
59
60 dwLength = dwPrevLen;
61 dwLength &= 3;
62
63 while (dwLength--)
64 *lpbyDestination++ = 0;
65}
66