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

📄 test_memory.c

📁 This a framework to test new ideas in transmission technology. Actual development is a LDPC-coder in
💻 C
字号:
/***************************************************************************         memory.c  -  Testmodule for software radio memory allocation                            -------------------    begin                :  2002    authors              :  Silvio Boehler    emails               :  sboehler@student.ethz.ch ***************************************************************************//***************************************************************************                                 Changes                                 ------- date - name - description 02/x/x - sboehler - start 04/03/03 - ineiti - added a short description  **************************************************************************//*************************************************************************** *                                                                         * *   This program is free software; you can redistribute it and/or modify  * *   it under the terms of the GNU General Public License as published by  * *   the Free Software Foundation; either version 2 of the License, or     * *   (at your option) any later version.                                   * *                                                                         * ***************************************************************************//** * Debugging: */#include "system.h"#include "debugging.h"#define DBG_LVL 4char desc[] ="Description:\n""Does different kind of memory-allocations and tests for the correct\n""working of this subsystem. First it stores 20 strings using swr_malloc\n""and displays them: 'This is string number (1-20)!!!'\n""Then it allocates a given memory-size multiple times and displays the\n""alignement of these memory-blocks. The alignement should be a multiple\n""of 0x20, at least.\n\n";/** * The interface for this module */#include "memory.h"#define STRING_LENGTH 100#define NBR_STRINGS 20pthread_t thread;void work(void) {  int i, j;  char my_string[STRING_LENGTH] = "This is string number %i!!!\n";  char *new_strings[NBR_STRINGS];  PR_DBG( 0,  "Starting test 1\n" );  for (i = 0; i < NBR_STRINGS; i++) {    new_strings[i] = (char *)swr_malloc(STRING_LENGTH);    for (j = 0; j < STRING_LENGTH; j++) {      new_strings[i][j] = my_string[j];    }    PR_DBG_CL( 0, new_strings[i], i );  }  for (i = 0; i < NBR_STRINGS; i++) {    swr_free(new_strings[i]);  }}void work2(void) {  void *m[11];  int i;  for (i=0; i<11; i++ ) {    m[i]=swr_malloc( 16 );  }  for (i=0; i<10; i++ ) {    swr_free( m[i] );  }  swr_memory_show();  PR_DBG( 0, "allocate 16 bytes\n");  m[0] = swr_malloc( 16 );  PR_DBG( 0, "The address is %p\n", m[0]);  swr_memory_show();}#define ALIGN_COUNT 8void test_align( void ) {  void *a[ALIGN_COUNT];  int i, j;  for ( i=1; i < ( 1 << 20 ); i *= 2 ) {    PR_DBG( 0, "%6i: ", i );    for ( j=0; j<ALIGN_COUNT; j++ ){      a[j] = swr_malloc( i );      PR_DBG_CL( 0, "%2x - ", (unsigned int)a[j] & 0xff );    }    PR_DBG_CL( 0, "\n" );    for ( j=0; j<ALIGN_COUNT; j++ ){      swr_free( a[j] );    }  }}void test_bigalloc( void ){  int nbr_blocks = 10, block, size;  void *d[nbr_blocks];  PR_DBG( 0, "\nTesting big-allocation\n" );  // Loop from 2^16 to 2^31 and try to alloc nbr_blocks and free them  for ( size = 24; size < 25; size++ ){    PR_DBG( 0, "Testing size 2^%i\n", size );    for ( block = 0; block < nbr_blocks; block++ ){      d[block] = swr_malloc( 1 << size );      if ( !d[block] ){	PR_DBG( 0, "Couldn't allocate block nr %i from size 2^%i\n",		block, size );	break;      }    }    for ( block--; block >= 0; block-- ){      if ( swr_free( d[block] ) ){	PR_DBG( 0, "Problem while freeing block nr %i from size 2^%i\n",		block, size );      }    }    swr_memory_show();    PR_DBG( 0, "Testing again size 2^%i\n", size );    for ( block = 0; block < nbr_blocks; block++ ){      d[block] = swr_malloc( 1 << size );      if ( !d[block] ){	PR_DBG( 0, "Couldn't allocate block nr %i from size 2^%i\n",		block, size );	break;      }    }    for ( block--; block >= 0; block-- ){      if ( swr_free( d[block] ) ){	PR_DBG( 0, "Problem while freeing block nr %i from size 2^%i\n",		block, size );      }    }    swr_memory_show();  }}void *test_all(void *arg) {  PR_CL( desc );  work();  usleep( 100000 );  work2();  usleep( 100000 );  test_align();  usleep( 100000 );  test_bigalloc();  return 0;}int initialize(void) {  pthread_create(&thread, 0, test_all, 0);  return 0;}void finalize(void) {  pthread_join( thread, NULL );  pthread_cancel( thread );}module_init(initialize);module_exit(finalize);

⌨️ 快捷键说明

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