Std :: ostringstream 2 ГБ крышка в Windows?C++

Программы на C++. Форум разработчиков
Ответить Пред. темаСлед. тема
Anonymous
 Std :: ostringstream 2 ГБ крышка в Windows?

Сообщение Anonymous »

Я вставляю ниже минимальный пример, который записывает в объект std :: string , а также в объект std :: ostringstream , 0,5 ГБ за раз, затем запрашивает и печатает их размеры на каждом шаге.Step 1 | std::string size: 0.5 GB | ostringstream size: 0.5 GB
Step 2 | std::string size: 1 GB | ostringstream size: 1 GB
Step 3 | std::string size: 1.5 GB | ostringstream size: 1.5 GB
Step 4 | std::string size: 2 GB | ostringstream size: 2 GB
Step 5 | std::string size: 2.5 GB | ostringstream size: 2 GB
Step 6 | std::string size: 3 GB | ostringstream size: 2 GB
Finished writing 3 GB to files.


Когда выполняется на любой другой ОС, например, macos с GCC или Clang, OstringStream не ограничен:
macos с GCC или Clang, OstringStream не ограничивается:
macos с GCC или Clang, OstringsTream:Step 1 | std::string size: 0.5 GB | ostringstream size: 0.5 GB
Step 2 | std::string size: 1 GB | ostringstream size: 1 GB
Step 3 | std::string size: 1.5 GB | ostringstream size: 1.5 GB
Step 4 | std::string size: 2 GB | ostringstream size: 2 GB
Step 5 | std::string size: 2.5 GB | ostringstream size: 2.5 GB
Step 6 | std::string size: 3 GB | ostringstream size: 3 GB
Finished writing 3 GB to files.

Является ли std :: ostringstream неправильно, заполненная Microsoft? Согласно всем источникам, std :: ostringstream должна быть оберткой вокруг std :: string и должен иметь максимальный размер, равный максимальной длине строки.
исходный код (stringwriter.cpp):
#include
#include
#include
#include
#include

constexpr std::size_t HALF_GB = 512 * 1024 * 1024; // 0.5 GB in bytes
constexpr std::size_t THREE_GB = 3ULL * 1024 * 1024 * 1024; // 3 GB in bytes

int main() {
std::string str;
std::ostringstream oss;

// Block for 0.5GB, filled with 'A'
std::string block(HALF_GB, 'A');

std::size_t current_size = 0;
int step = 0;

while (current_size < THREE_GB) {
++step;
// Append to std::string
str.append(block);

// Append to std::ostringstream
oss.write(block.data(), block.size());

// Query actual sizes
std::size_t str_size = str.size();
std::size_t oss_size = oss.str().size();

current_size = str_size; // Since both should grow equally

std::cout

Подробнее здесь: https://stackoverflow.com/questions/797 ... on-windows
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «C++»