我一直在测试自己的一些代码,以查看耗尽堆或空闲存储上的内存需要多少已分配内存。但是,除非我的代码在测试中是错误的,否则我会在堆上可以放置多少内存方面得到完全不同的结果。
我正在测试两个不同的程序。第一个程序在堆上创建矢量对象。第二个程序在堆上创建整数对象。
这是我的代码:
#include <vector>
#include <stdio.h>
int main()
{
long long unsigned bytes = 0;
unsigned megabytes = 0;
for (long long unsigned i = 0; ; i++) {
std::vector<int>* pt1 = new std::vector<int>(100000,10);
bytes += sizeof(*pt1);
bytes += pt1->size() * sizeof(pt1->at(0));
megabytes = bytes / 1000000;
if (i >= 1000 && i % 1000 == 0) {
printf("There are %d megabytes on the heap\n", megabytes);
}
}
}
Run Code Online (Sandbox Code Playgroud)
出现bad_alloc错误之前,此代码的最终输出是:“堆上有2000 MB”
在第二个程序中:
#include <stdio.h>
int main()
{ …Run Code Online (Sandbox Code Playgroud) 问题:
我正在使用 Firebase Cloud Functions 制作一个网络应用程序。我目前已将 Firebase 连接到我的项目的后端。但是,我需要允许用户上传大约 50MB 左右的文件。
不幸的是,我最近才发现 Firebase Cloud Functions 的最大 HTTP 请求大小为 10MB。

出于安全目的,我有安全规则(显然),因此我不能允许任何人将任何内容上传到 Firebase 存储或 Firestore。由于用户在后端而不是前端进行身份验证,因此我无法在不触发安全规则的情况下使用 Firebase 功能上传到 Firebase 存储和 Firestore。
当我想要保持 Firebase 连接到后端时,对于此类问题有什么好的解决方案吗?谢谢。
file-upload firebase firebase-authentication google-cloud-functions firebase-storage