ccmem.cc

Go to the documentation of this file.
00001 /* MLPACK 0.2
00002  *
00003  * Copyright (c) 2008, 2009 Alexander Gray,
00004  *                          Garry Boyer,
00005  *                          Ryan Riegel,
00006  *                          Nikolaos Vasiloglou,
00007  *                          Dongryeol Lee,
00008  *                          Chip Mappus, 
00009  *                          Nishant Mehta,
00010  *                          Hua Ouyang,
00011  *                          Parikshit Ram,
00012  *                          Long Tran,
00013  *                          Wee Chin Wong
00014  *
00015  * Copyright (c) 2008, 2009 Georgia Institute of Technology
00016  *
00017  * This program is free software; you can redistribute it and/or
00018  * modify it under the terms of the GNU General Public License as
00019  * published by the Free Software Foundation; either version 2 of the
00020  * License, or (at your option) any later version.
00021  *
00022  * This program is distributed in the hope that it will be useful, but
00023  * WITHOUT ANY WARRANTY; without even the implied warranty of
00024  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00025  * General Public License for more details.
00026  *
00027  * You should have received a copy of the GNU General Public License
00028  * along with this program; if not, write to the Free Software
00029  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00030  * 02110-1301, USA.
00031  */
00041 #include "fastlib/base/ccmem.h"
00042 
00043 const int32 mem__private::BIG_BAD_BUF[] = {
00044   BIG_BAD_NUMBER,
00045   BIG_BAD_NUMBER,
00046   BIG_BAD_NUMBER,
00047   BIG_BAD_NUMBER,
00048   BIG_BAD_NUMBER,
00049   BIG_BAD_NUMBER,
00050   BIG_BAD_NUMBER,
00051   BIG_BAD_NUMBER,
00052   BIG_BAD_NUMBER,
00053   BIG_BAD_NUMBER,
00054   BIG_BAD_NUMBER,
00055   BIG_BAD_NUMBER,
00056   BIG_BAD_NUMBER,
00057   BIG_BAD_NUMBER,
00058   BIG_BAD_NUMBER,
00059   BIG_BAD_NUMBER
00060 };
00061 
00062 void mem__private::PoisonBytes(char *array_cp, size_t bytes) {
00063   while (bytes >= BIG_BAD_BUF_SIZE) {
00064     ::memcpy(array_cp, BIG_BAD_BUF, BIG_BAD_BUF_SIZE);
00065 
00066     bytes -= BIG_BAD_BUF_SIZE;
00067     array_cp += BIG_BAD_BUF_SIZE;
00068   }
00069   if (bytes > 0) {
00070     ::memcpy(array_cp, BIG_BAD_BUF, bytes);
00071   }
00072 }
00073 
00074 void mem__private::SwapBytes(char *a_cp, char *b_cp, size_t bytes) {
00075   char buf[SWAP_BUF_SIZE];
00076 
00077   while (bytes >= SWAP_BUF_SIZE) {
00078     ::memcpy(buf, a_cp, SWAP_BUF_SIZE);
00079     ::memcpy(a_cp, b_cp, SWAP_BUF_SIZE);
00080     ::memcpy(b_cp, buf, SWAP_BUF_SIZE);
00081 
00082     bytes -= SWAP_BUF_SIZE;
00083     a_cp += SWAP_BUF_SIZE;
00084     b_cp += SWAP_BUF_SIZE;
00085   }
00086   if (bytes > 0) {
00087     ::memcpy(buf, a_cp, bytes);
00088     ::memcpy(a_cp, b_cp, bytes);
00089     ::memcpy(b_cp, buf, bytes);
00090   }
00091 }
Generated on Mon Jan 24 12:04:37 2011 for FASTlib by  doxygen 1.6.3