Ticket #1433: pespacket_block_allocation.patch

File pespacket_block_allocation.patch, 1.9 KB (added by Janne <janne-mythtv@…>, 20 years ago)
  • libs/libmythtv/mpeg/pespacket.cpp

     
    135135static vector<unsigned char*> free4096;
    136136static map<unsigned char*, bool> alloc4096;
    137137
    138 #define BLOCKS188 1000
     138#define BLOCKS188 512
    139139static unsigned char* get_188_block()
    140140{
    141     if (!free188.size())
     141    if (free188.empty())
    142142    {
    143143        mem188.push_back((unsigned char*) malloc(188 * BLOCKS188));
    144144        free188.reserve(BLOCKS188);
     145        unsigned char* block_start = mem188.back();
    145146        for (uint i = 0; i < BLOCKS188; ++i)
    146             free188.push_back(i*188 + mem188.back());
     147            free188.push_back(i*188 + block_start);
    147148    }
    148149
    149150    unsigned char *ptr = free188.back();
     
    163164    alloc188.erase(ptr);
    164165    if (alloc188.size())
    165166        free188.push_back(ptr);
    166     else
     167    // free the allocator only if more than 1 block was used
     168    else if (mem188.size() > 1)
    167169    {
    168170        vector<unsigned char*>::iterator it;
    169171        for (it = mem188.begin(); it != mem188.end(); ++it)
     
    174176    }
    175177}
    176178
    177 #define BLOCKS4096 256
     179#define BLOCKS4096 128
    178180static unsigned char* get_4096_block()
    179181{
    180     if (!free4096.size())
     182    if (free4096.empty())
    181183    {
    182184        mem4096.push_back((unsigned char*) malloc(4096 * BLOCKS4096));
    183185        free4096.reserve(BLOCKS4096);
     186        unsigned char* block_start = mem4096.back();
    184187        for (uint i = 0; i < BLOCKS4096; ++i)
    185             free4096.push_back(i*4096 + mem4096.back());
     188            free4096.push_back(i*4096 + block_start);
    186189    }
    187190
    188191    unsigned char *ptr = free4096.back();
     
    221224        }
    222225#endif
    223226    }
    224     else
     227    // free the allocator only if more than 1 block was used
     228    else if (mem4096.size() > 1)
    225229    {
    226230        vector<unsigned char*>::iterator it;
    227231        for (it = mem4096.begin(); it != mem4096.end(); ++it)