When you put something into a dynamic array, it won't grow by just 1 when reaching the limit. This is important because changing size is an expensive operation.
For example if I have a job to execute, and the input data just keep coming and coming every now and then.
There could be 2 models for this:
Solution #1: Keep a timeout for the job, extend the execution time by fixed time(such as 1s) every time we received a new job. When timeout is reached, execute the job.
When a new input come, and there's no existing job available, we simple create a new job
Solution #2: Keep a timeout for the tob, before execution, collect new inputs, before execution in the last second, mark it as silent period. If we have new input coming in the silent period, do not execute the job, request another spin of time as the timeout is defined.
本文探讨了处理连续输入数据的两种模型:通过设置定时器扩展执行时间以响应每个新任务,或在沉默期收集输入并在定时器结束时执行任务,以优化资源使用和效率。

257

被折叠的 条评论
为什么被折叠?



