Пример #1
0
int main()
{
	printf("Before allocation:\n");
	printf("Total memory: %u bytes\n", getTotalMemory());
	printf("Free memory: %u bytes\n", getFreeMemory());
	printf("Used: %u bytes (%.2f%%)\n", getTotalMemory() - getFreeMemory(), (getTotalMemory() - getFreeMemory()) * 100.0 / getTotalMemory());
	assert(getTotalMemory() == 16777216);
	assert(getFreeMemory() >= 10000000); // 11529552 in test

	void *ptr = malloc(1024*1024);
	printf("\nAfter 1MB allocation:\n");
	printf("Total memory: %u bytes\n", getTotalMemory());
	printf("Free memory: %u bytes\n", getFreeMemory());
	printf("Used: %u bytes (%.2f%%)\n", getTotalMemory() - getFreeMemory(), (getTotalMemory() - getFreeMemory()) * 100.0 / getTotalMemory());
	assert(getTotalMemory() == 16777216);
	assert(getFreeMemory() >= 9000000); // 10480968 in test

	free(ptr);
	printf("\nAfter freeing:\n");
	printf("Total memory: %u bytes\n", getTotalMemory());
	printf("Free memory: %u bytes\n", getFreeMemory());
	printf("Used: %u bytes (%.2f%%)\n", getTotalMemory() - getFreeMemory(), (getTotalMemory() - getFreeMemory()) * 100.0 / getTotalMemory());
	assert(getTotalMemory() == 16777216);
	assert(getFreeMemory() >= 10000000); // 11529552 in test

	printf("OK.\n");
}
Пример #2
0
/**
 * Checks for the new minimum memory
 */
void memoryCheck()
{
    int free_memory = getFreeMemory();

    if (free_memory < memory_min) memory_min = free_memory;

    return;
}
Пример #3
0
void showMemory(void) {
  char buffer[100];

  snprintf(buffer, sizeof(buffer), "%04u %04u %04u : used/free/large",
      getMemoryUsed(),
      getFreeMemory(),
      getLargestAvailableMemoryBlock()
    );

  speol(buffer);
}
Пример #4
0
uint8_t MEMaction (uint8_t source) {
    if (consoleComm.verb=='?') {
        int memory;
        memory=getFreeMemory();
        toConsole("MEM:%ld",memory);;
        return COMMAND_OK;
    } else {
        toConsole("NAK:");
        return COMMAND_ERROR;
    }

}
Пример #5
0
float Client::getMemoryUsage() {
  int free_mem = getFreeMemory();
  int total_mem = getAllMemory();
  return 100 - (free_mem / ((float)total_mem)) * 100;
}
/*==============================================================================
* writeRead
*
* One step read and write to Exosite using Particle String objects.
*=============================================================================*/
boolean Exosite::writeRead(const String &writeString, const String &readString, String &returnString){
  #if EXOSITEDEBUG > 2
    Serial.print(getFreeMemory());
    Serial.println(F(" = Free Memory String Start"));
    Serial.println(writeString);
    Serial.println(readString);
  #endif

  char *writeCharString, *readCharString, *returnCharString;
  writeCharString = (char*)malloc(sizeof(char) * writeString.length()+1);
  readCharString = (char*)malloc(sizeof(char) * readString.length()+1);
  returnCharString = (char*)malloc(sizeof(char) * 32);

  #if EXOSITEDEBUG > 2
    Serial.print(getFreeMemory());
    Serial.println(F(" = Free Memory String Chars Allocated"));
    Serial.print(F("Return Address Before: "));
    Serial.println((intptr_t)returnCharString);
  #endif

  if(writeCharString == 0 || readCharString == 0 || returnCharString == 0){
    Serial.println(F("Not Enough Ram! Failing!"));
    while(1);
  }

  writeString.toCharArray(writeCharString, writeString.length()+1);
  readString.toCharArray(readCharString, readString.length()+1);


  #if EXOSITEDEBUG > 2
    Serial.print(getFreeMemory());
    Serial.println(F(" = Free Memory String Start Char Write"));
  #endif

  if(this->writeRead(writeCharString, readCharString, &returnCharString)){

    #if EXOSITEDEBUG > 2
      Serial.print(getFreeMemory());
      Serial.println(F(" = Free Memory String Char Write Finished"));
      Serial.print(F("Return Address After: "));
      Serial.println((intptr_t)returnCharString);
    #endif

    returnString = returnCharString;


    #if EXOSITEDEBUG > 2
      Serial.print(getFreeMemory());
      Serial.println(F(" = Free Memory String Chars Copied"));
    #endif

    ret = true;
  }else{
    Serial.println(F("Error Communicating with Exosite"));
    ret = false;
  }
  free(writeCharString);
  free(readCharString);
  free(returnCharString);


  #if EXOSITEDEBUG > 2
    Serial.print(getFreeMemory());
    Serial.println(F(" = Free Memory String Chars Freed"));
  #endif

  return ret;
}