Esempio n. 1
0
typename allocator<T>::size_type allocator<T>::find_free_memory(const dynamic_bitset & memfree, dynamic_bitset & mask)
{
	/* search mask in memfree */
	const size_type needed_mem_size = mask.count();
	if (memfree.count() < needed_mem_size) {
#		if DEBUG_SMA_TRACE_FIND_FREE_MEM
		std::cout << "not enough free memory found" << std::endl;
#		endif
		return memfree.size();
	}
	assert(needed_mem_size <= memfree.size());
	const size_type asize = memfree.size() - needed_mem_size;
	size_type pos = 0;
	while (pos <= asize) {
#		if DEBUG_SMA_TRACE_FIND_FREE_MEM
		std::cout << "pos:     " << pos << "/" << asize << std::endl;
		std::cout << "mask:    " << mask << std::endl;
		std::cout << "memfree: " << memfree << std::endl;
#		endif
		/* check if enough memory is free in interval [pos, pos+needed_mem_size) */
		if ((memfree & mask) == mask) {
			/* free memory found */
#			if DEBUG_SMA_TRACE_FIND_FREE_MEM
			std::cout << "free memory found at pos=" << pos << std::endl;
#			endif
			return pos;
		} else {
			/* increment pos for next iteration */
#			if DEBUG_SMA_TRACE_FIND_FREE_MEM
			std::cout << "memfree:  " << memfree << "    "
				  << memfree << std::endl;
			std::cout << "inc mask: " << mask << " -> ";
#			endif
			const size_type oldpos = pos;
			pos = memfree.find_next(oldpos);
			assert(pos >= oldpos);
			mask <<= pos - oldpos;
#			if DEBUG_SMA_TRACE_FIND_FREE_MEM
			std::cout << mask << std::endl;
			std::cout << "pos: " << oldpos << " -> "
				  << pos << std::endl;
#			endif
			assert(mask.count() == needed_mem_size);
		}
	}
	/* no free memory found */
#	if DEBUG_SMA_TRACE_FIND_FREE_MEM
	std::cout << "not enough free memory found" << std::endl;
#	endif
	return memfree.size();
}
Esempio n. 2
0
typename allocator<T>::dynamic_bitset allocator<T>::free_memory(const dynamic_bitset & memfree,
	                                                        dynamic_bitset && mask)
{
	assert(memfree.size() == mask.size());
	assert(memfree.count() + mask.count() <= memfree.size());
	auto res = memfree | mask;
#	if DEBUG_SMA_TRACE_BITSET
	std::cout << "a=memfree: " << memfree << std::endl;
	std::cout << "b=   mask: " << mask << std::endl;
	std::cout << "r=  a | b: " << res << std::endl;
#	endif
	assert(memfree.count() + mask.count() == res.count());
	return res;
}
void print(const dynamic_bitset<>& items, ostream& out) {
	out << "{ ";
	for(dynamic_bitset<>::size_type i = items.find_first(); i != items.npos; i = items.find_next(i)){
		out << i << " ";
	}
	out << "} -- " << items.count() << endl;
}
Esempio n. 4
0
void add_unique(list<dynamic_bitset<> >& masks,const list<dynamic_bitset<> >& old_masks,
		const dynamic_bitset<>& mask) 
{
    // don't add the mask unless contains internal partitions (it could be all 0)
    if (mask.count() < 4) return;

    // don't add the mask if we already have that mask
    for(const auto& m: old_masks)
	if (m == mask) return;

    for(const auto& m: masks)
	if (m == mask) return;

    // otherwise, add the mask
    masks.push_front(mask);
}