Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Zortech C++ 3.0r4 - <b>the memory package</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
The Memory Package

   This is a set of ANSI C functions for manipulating memory buffers. They
   are very closely related to the functions in the String package but do not

   expect a buffer to be null terminated.

   Memory package functions expect their pointer arguments to match the
   memory model in use. Do not use explicit near or far pointers unless this is
   the case.

   The Memory package can be split into three functional groups and some
   miscellaneous function, as follows:

Copying Functions

   Two functions are provided for copying blocks of memory, memcpy and
   memmove. These are generally equivalent except that memcpy cannot
   handle overlapping moves. memmove can do this, but is slower in
   operation.

Comparison Functions

   Two comparison functions are provided which allow blocks of memory to be
   compared, memcmp and memicmp. The difference here is that memcmp treats

   upper and lower case as distinct whereas memicmp does not.

Search Functions

   A single function memchr locates the first occurrence of a byte in a memory
   block.

Miscellaneous Functions

   The function memset is used to set a block of memory to a known value.
   This could be used to clear all bytes in the block to zero, for instance.

Example 

   #include <string.h>
   #include <stdio.h>
   #include <stdlib.h>

   char srccpy[] = "Sample string 2\n";

   int main()
   {
       char buffer[50];
       char buffer2[50];
       char *result;
       int reslt;

       strcpy(buffer2,"Sample String\n");
       printf("memcpy function in progress\n");
       memcpy(buffer,buffer2,15);
       printf("memchr function in progress\n");
       result = memchr(buffer,'t',50);
       if(result != NULL)
           printf("Character (t) found at (%d)\n",
       result - buffer +1);
       else
           printf("Error - (t) not found\n");
       printf("memcmp function in progress\n");
       reslt = memcmp(buffer,buffer2,50);
       printf("The result of memcmp is: %s\n",reslt);

       printf("memicmp function in progress\n");
       reslt = memicmp(buffer,buffer2,50);
       printf("The result of memicmp is: %s\n",reslt);
       printf("buffer before memmove: %s",buffer);
       result = memmove(buffer,srccpy,sizeof(srccpy));
       printf("buffer after memmove: %s",buffer);
       printf("buffer before memset: %s",buffer);
       result = memset(buffer,'x',6);
       printf("buffer after memset: %s",buffer);
       return EXIT_SUCCESS;
   }

See Also

   movedata, peek, poke, The String Package



See Also: movedata peek poke str

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson