mirror of
				https://github.com/ton-blockchain/ton
				synced 2025-03-09 15:40:10 +00:00 
			
		
		
		
	- updated func/fift - additional checks in block validator - docs - tunnel prototype in ADNL
		
			
				
	
	
		
			50 lines
		
	
	
	
		
			1.4 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			50 lines
		
	
	
	
		
			1.4 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
/*
 | 
						|
    This file is part of TON Blockchain Library.
 | 
						|
 | 
						|
    TON Blockchain Library is free software: you can redistribute it and/or modify
 | 
						|
    it under the terms of the GNU Lesser General Public License as published by
 | 
						|
    the Free Software Foundation, either version 2 of the License, or
 | 
						|
    (at your option) any later version.
 | 
						|
 | 
						|
    TON Blockchain Library is distributed in the hope that it will be useful,
 | 
						|
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
						|
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
						|
    GNU Lesser General Public License for more details.
 | 
						|
 | 
						|
    You should have received a copy of the GNU Lesser General Public License
 | 
						|
    along with TON Blockchain Library.  If not, see <http://www.gnu.org/licenses/>.
 | 
						|
 | 
						|
    Copyright 2020 Telegram Systems LLP
 | 
						|
*/
 | 
						|
namespace td {
 | 
						|
 | 
						|
class LinearAllocator {
 | 
						|
  std::size_t size;
 | 
						|
  char *ptr, *cur, *end;
 | 
						|
 | 
						|
 public:
 | 
						|
  LinearAllocator(std::size_t _size) : size(_size) {
 | 
						|
    cur = ptr = (char*)malloc(size);
 | 
						|
    if (!ptr) {
 | 
						|
      throw std::bad_alloc();
 | 
						|
    }
 | 
						|
    end = ptr + size;
 | 
						|
  }
 | 
						|
  ~LinearAllocator() {
 | 
						|
    free(ptr);
 | 
						|
  }
 | 
						|
  void* allocate(std::size_t count) {
 | 
						|
    char* t = cur;
 | 
						|
    cur += (count + 7) & -8;
 | 
						|
    if (cur > end) {
 | 
						|
      throw std::bad_alloc();
 | 
						|
    }
 | 
						|
    return (void*)t;
 | 
						|
  }
 | 
						|
};
 | 
						|
 | 
						|
}  // namespace td
 | 
						|
 | 
						|
inline void* operator new(std::size_t count, td::LinearAllocator& alloc) {
 | 
						|
  return alloc.allocate(count);
 | 
						|
}
 |