Skip to content
Snippets Groups Projects
Select Git revision
  • 0532f9be37ca66c68d98d1a68530a17041c11fc2
  • master default protected
  • release-3.2.3
  • alpha-3.2.0
  • darkaudacity
  • mac-2.1.1-vi
  • DarkAudacity-2.3.2x
  • Audacity-2.3.2
  • Audacity-2.3.1
  • Audacity-2.3.0
  • Audacity-2.2.2
  • Audacity-2.2.2-beta-20180128
  • Audacity-2.2.1
  • Audacity-2.2.1-rc3
  • Audacity-2.2.1-rc2
  • Audacity-2.2.1-rc1
  • Audacity-2.2.0
  • Audacity-2.2.0-rc1
  • Audacity-2.2.0-beta-20170901
  • Audacity-2.1.3
  • DarkAudacity-2.1.3x
  • Audacity-2.1.2
  • wx3-stable
  • wx3-unstable
  • Audacity-2.1.1
  • Audacity-2.1.0
26 results

DirManager.cpp

Blame
  • alloc.c 3.26 KiB
    #include "alloc.h"
    
    #include <stdio.h>
    #include <stdint.h>
    #include <string.h>
    
    void *m_malloc(uint32_t size){
      meta* temp;
      if(size%4 != 0)
        size += (4-size%4);
    
      if(head == NULL){
        temp = sbrk(size);
        temp -> next_memory = NULL;
        temp -> prev_memory = NULL;
        temp -> size = size;
        temp -> free = 0;
        strcpy(temp -> comment,tmp_comment);
        temp -> fit= fit;
    
        head = temp;
        first = temp;
      }
      else{
        meta* prev = NULL;
        meta* next = NULL;
        meta* tmp_head = head;
          while(1){
    	if(tmp_head->next_memory == NULL){
    	  if(prev == NULL){
    	    prev = tmp_head;
    	  }
    	  break;
    	}
    	else if(tmp_head -> next_memory -> free == 1 && tmp_head -> next_memory -> size > size){
              if( prev == NULL){
    	    prev = tmp_head;
    	    if(fit == "F")
    	      break;
    	  }
    	  else{
    	    if(fit == "B")
    	      prev = (prev -> size < tmp_head -> next_memory -> size) ? prev : tmp_head;
    	    else if(fit == "W")
    	      prev = (prev -> size > tmp_head -> next_memory -> size) ? prev : tmp_head;
    	  }
    	}
    	tmp_head = tmp_head-> next_memory;
          }
        tmp_head = prev -> next_memory;
        next = tmp_head -> next_memory;
        if(tmp_head -> size == size){
          prev -> next_memory -> free = 0;
        }
        else{
          temp -> prev_memory = prev;
          temp -> next_memory = tmp_head;
          temp -> size = size;
          temp -> free = 0;
          strcpy(temp -> comment,tmp_comment);
          temp -> fit = fit;
    
          tmp_head -> size -= size; 
          tmp_head -> prev_memory = temp;
    
          prev -> next_memory = temp;
        }
      }
    }
    
    void m_realoc(void* p,uint32_t size){
      if(size%4 != 0)
        size += (4-size%4);
    
      int index = *(int *)p;
      int count = 0;
      meta* temp = head;
    
      while(1){
        if(count == index)
          break;
        
        temp = temp -> next_memory;
        if(temp -> free == 0)
          count++;
      }
      if(temp -> next_memory == NULL){
        temp -> size = size;
      }
      else if(size < (temp -> next_memory -> size) + temp -> size){
    	temp -> next_memory -> size -= (size - temp->size);
    	temp -> size = size;
      }
      else if(size = (temp -> next_memory -> size) + temp -> size){
      	temp -> size = size;
    	temp -> next_memory = temp -> next_memory -> next_memory;
      }
      else
        m_malloc(size);
    }
    
    void m_free(void *ptr){
      int index = *(int *)ptr;
      int count = 0;
      meta* tmp_head;
      meta* temp = head;
      int size = head -> size;
      int break_point = 0;
       
        if(temp -> next_memory != NULL){
          if(temp -> next_memory -> free == 1){
            size += temp -> next_memory -> size;
            tmp_head -> next_memory = temp -> next_memory -> next_memory;
    	temp -> next_memory -> next_memory -> prev_memory = tmp_head;
          }
        }
        else
          tmp_head -> next_memory = NULL;
          
        if(temp -> prev_memory != NULL){
          if(temp -> prev_memory -> free == 1){
            size += temp -> prev_memory -> size;
            tmp_head -> prev_memory = temp -> prev_memory -> prev_memory;
    	temp -> prev_memory -> prev_memory -> next_memory = tmp_head;
          }
        }
        else
          tmp_head -> prev_memory = NULL;
        
      tmp_head -> free = 1;
      tmp_head -> size = size;
      strcpy(temp -> comment," ");
      if( index == 0)
        head == tmp_head -> next_memory;
    }
    
    
    void read(){
      meta* temp = first;
      
      while(1){
        if(temp -> next_memory == NULL)
          break;
    
        printf("%d %d %s\n", temp -> free, temp -> size, temp -> comment);
      }
    }