首页 \ 问答 \ C ++运行时是什么意思?(What does it mean by C++ runtime?)

C ++运行时是什么意思?(What does it mean by C++ runtime?)

C ++运行时完成的所有活动是什么?


What are all the activities done by C++ runtime?


原文:https://stackoverflow.com/questions/1824533
更新时间:2023-03-06 21:03

最满意答案

将方法作为静态运行是安全的,只要它不依赖于静态方法之外的静态变量即可。

这里是一个如何在asp.net Web应用程序中不使用静态的示例:

    public static string SaveSomething;
    public static void DoSomething()
    {
        SaveSomething = "something";
        //... do more code
        AnotherAction(SaveSomething);
    }

首先,SaveSomething字符串属性设置为您的值。 同时,该属性可以由另一个请求/用户设置,因为它共享该属性。 现在,如果您回忆该属性并将其用于AnotherAction,则它可能与您最初设置的值不同。 如果要使用对外部静态变量的引用,则必须确保这些变量以这种方式安全使用。 大多数情况下它们是只读的。

但是可以使用lock语句锁定属性:

    public static string SaveSomething;
    public static void DoSomething()
    {
        lock (SaveSomething)
        {
             SaveSomething = "something";
             //... do more code
             AnotherAction(SaveSomething);
        }
    }

lock关键字通过获取给定对象的互斥锁,执行语句,然后释放锁来将语句块标记为关键部分。


It is safe to run your method as a static, as long as it does not depend on static variables that are outside of your static method.

Here a example of how not to use statics in asp.net web applications:

    public static string SaveSomething;
    public static void DoSomething()
    {
        SaveSomething = "something";
        //... do more code
        AnotherAction(SaveSomething);
    }

First the SaveSomething string property is set to your value. In the meanwhile this property could be set by another request/user because it shares the property. Now if you recall the property and use it for AnotherAction it may not be the same value as you initially set. If you want to use references to external static variables, you have to be sure those variables are safe to use in that manner. Most of the cases they are read only.

However it is possible to lock the property with the lock statement:

    public static string SaveSomething;
    public static void DoSomething()
    {
        lock (SaveSomething)
        {
             SaveSomething = "something";
             //... do more code
             AnotherAction(SaveSomething);
        }
    }

The lock keyword marks a statement block as a critical section by obtaining the mutual-exclusion lock for a given object, executing a statement, and then releasing the lock.

相关问答

更多
  • 反思允许恶意代码检查各种秘密:不是那么多的知识产权(尽管确实如此),但应该是私密和安全的数据,如连接字符串,密码,银行账户数据等。 当然,许多程序通过更容易受损的向量公开这些数据,但是没有理由增加应用程序的攻击面。 编辑从评论中提出一些对话: 真正的风险可能是无限制的文件系统访问,这将反射转化为真正的危险。 如果一个坏角色可以将一个程序集(或者被编译成程序集的东西)加入到你的虚拟目录中,那么如果他们有反映许可,你就会遇到麻烦。 (当然,如果发生这种情况,还有其他潜在的问题,但不应该打折这个特定的漏洞。) 在 ...
  • 我会说,只要项目本身稳定而且你喜欢,所谓的“死亡”项目就不是那么危险。 问题是,如果图书馆或框架已经做了你能想到的所有事情,那么这不是什么大不了的事情。 如果你得到一个稳定的项目并运行,那么你应该考虑框架(完成!),并只关注你的 web应用程序。 您不应该被要求每月更新最新版本的框架。 就我个人而言,我认为最重要的一点是你找到了一个对你的项目直观的。 最有意义的是什么? MVC? 网址中的每个元素应该是一个单独的对象吗? 交互性(AJAX)如何工作? 选择一些东西是没有意义的,因为它是一个“行业标准”,或者 ...
  • 您可以使用数据库,自定义数据源(由DataSource接口包装的简单列表)等等,但...... Web应用程序的任何实例 应该是any user of webapp ,对吧? You can use database, custom datasource (simple list wrapped by DataSource interface) and many more, but... any instance of the web application should it be any user of ...
  • 你不能。 [WebMethod]的重点是它们不运行ASP.Net页面生命周期。 这样,它们可以快速并且可并行化。 您的控件不存在。 相反,您应该使用Javascript(更好)或UpdatePanel(更糟糕)。 You can't. The whole point of [WebMethod]s is that they don't run the ASP.Net page lifecycle. This way, they're fast and parallelizable. Your control ...
  • 只需使用不等于运算符( <>或!=将在MySQL中工作)将它添加到where子句中。 下面的查询将返回所有不同的用户标识。 我添加了独特的,因为它似乎有多个行188和相同的用户标识,所以没有distinct ,你会多次获得相同的用户ID。 如果没有其他用户共享此猫,此查询将返回0行。 SELECT DISTINCT user_id FROM review_shared WHERE cat_id = ? AND user_id <> ? 如果你只是想知道有多少,你可以计算它。 下面的查询将返回一行, ...
  • 如果静态方法是同步的或具有某种形式的线程锁定,那么它将成为瓶颈。 但如果它是线程安全的,那么你应该没问题。 If the static method is synchronised or has some form of thread locking, then it will be a bottleneck. But if it is thread-safe, then you should be fine.
  • 您不能在Web服务中使用Shared (C#中的static )方法。 您可能会考虑在ASPX页面中将静态方法用作“页面方法”。 在独立的ASMX Web服务中,您只能使用实例方法。 You cannot use a Shared (static in C#) method in a web service. You may be thinking of the use of static methods as "page methods" in an ASPX page. In a standalone ...
  • 您为每个线程创建一个新的Calendar ,这很好,但是您在多个线程中使用SimpleDateFormat 。 如果该类是线程安全的, 那就没问题 , 但事实并非如此 。 SimpleDateFormat 因线程不安全而臭名昭着 。 只需为每次调用创建一个新的(即在方法中),或者更好的是,使用Joda-Time完全避免线程问题。 关于创建一个格式化程序类作为优化的主题,这是过早优化和无意结果的典型示例。 鉴于这是在JSP中,HTTP请求/响应时间将使新格式化程序的实例化时间(和资源要求)相形见绌。 使您的类 ...
  • 将方法作为静态运行是安全的,只要它不依赖于静态方法之外的静态变量即可。 这里是一个如何在asp.net Web应用程序中不使用静态的示例: public static string SaveSomething; public static void DoSomething() { SaveSomething = "something"; //... do more code AnotherAction(SaveSomething); ...
  • 是的,存在巨大的安全风险。 你所做的就是多租户申请 。 您必须采取特殊步骤以确保无法共享Cookie和其他敏感数据。 我的建议是将租户名称( portal1 )存储在表单身份验证cookie的自定义数据部分中。 您在发出表单cookie时设置自定义数据。 然后,有一个自定义模块或只是Application_AuthorizeRequest事件的处理Application_AuthorizeRequest ,其中已经基于cookie建立了标识。 在处理程序中,您从cookie中解密表单身份验证票证,检索用户数 ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。