格式和指针/十六进制值(内存覆盖)(Format and Pointers/Hex Values (Memory Overwrite))
在我的Delphi XE2 32位应用程序(Update 4 Hotfix 1 Version 16.0.4504.48759)中,我使用Format()例程来记录指针值。
例如:
Format('MyObject (%p)', [Pointer(MyObject)]);
但是,结果字符串有时包含垃圾字符(例如,在这种情况下,'?'或'|'代替十六进制数字):
MyObject (4E?|2010)
将'%p'替换为'%x'时,我也得到相同的结果:
Format('MyObject (%x)', [Integer(MyObject)]);
但是,使用整数值始终有效:
Format('MyObject (%d)', [Integer(MyObject)]); MyObject (1291453120)
是否存在我不知道的错误,或者这与此处遇到的问题有关?
除了“%s”以外的任何内容与Variant一起使用时,为什么Format会崩溃?
UPDATE
我已经接受了Jeroen的回答,因为它引导我通过消除过程来解决问题。 在通过F7启动应用程序的情况之后(根据评论),我认为在此过程中必须出现问题。 在预感,我禁用madExcept从其IDE菜单,重建应用程序,问题消失了。 显然,无论代码madExcept链接到我的应用程序是什么导致在SysUtils常量TwoHexLookup中覆盖。 重新启用madExcept和重建(我没有任何其他更改)也有效,因此在链接阶段必定存在一些损坏。
Jeroen用于检测内存损坏的策略是一项有用的练习,如果我遇到类似的情况,它应该证明是有价值的。
In my Delphi XE2 32-bit application (Update 4 Hotfix 1 Version 16.0.4504.48759) , I'm using the Format() routine to log pointer values.
For example:
Format('MyObject (%p)', [Pointer(MyObject)]);
However, the resulting string sometimes contains garbage characters (e.g., in this case '?' or '|' in place of hex digits):
MyObject (4E?|2010)
I also get the same result when replacing '%p' with '%x' like so:
Format('MyObject (%x)', [Integer(MyObject)]);
However, using an integer value always works:
Format('MyObject (%d)', [Integer(MyObject)]); MyObject (1291453120)
Is there a bug that I'm unaware of or can this be related to the problem experienced here?
Why does Format crash when anything but "%s" is used with a Variant?
UPDATE
I've accepted Jeroen's answer as it led me to the solution by process of elimination. After the situation with starting the app via F7 (as per the comment), I figured that something must be going wrong much earlier in the process. On a hunch, I disabled madExcept from its IDE menu, rebuilt the app, and the problem disappeared. Evidently, whatever code madExcept was linking into my application was causing an overwrite in the SysUtils constant TwoHexLookup. Re-enabling madExcept and rebuilding (without any other changes on my part) also worked, so there must have been some corruption during the linking phase.
The strategy Jeroen outlined for detecting memory corruption was a useful exercise and should prove valuable if I encounter a similar situation.
原文:https://stackoverflow.com/questions/14860985
最满意答案
您应该使用Jdbc连接池。 然后从代码中需要连接到数据库的任何地方,只需从池中获取与数据库的连接(连接池将负责维护与数据库的所需连接数)
例如,如果您使用BoneCP:
import com.jolbox.bonecp.BoneCP; import com.jolbox.bonecp.BoneCPConfig; import java.sql.Connection; import java.sql.SQLException; import java.sql.Statement; /** * <dependency> * <groupId>com.jolbox</groupId> * <artifactId>bonecp</artifactId> * <version>0.8.0.RELEASE</version> * </dependency> */ public class BoneCPexample { public static final int TOTAL_CONNECTIONS_TO_DATABASE = 20; public static void main(String[] args) throws SQLException { BoneCPexample boneCPexample = new BoneCPexample(); boneCPexample.doTheWork(); } private void doTheWork() throws SQLException { String jdbcUrlString = "jdbc:postgresql://localhost/test_database"; // jdbc:postgresql://host:port/database BoneCPConfig bcpConfig = new BoneCPConfig(); bcpConfig.setJdbcUrl(jdbcUrlString); bcpConfig.setUsername("postgres"); bcpConfig.setPassword("mi-password"); bcpConfig.setPartitionCount(1); bcpConfig.setMinConnectionsPerPartition(TOTAL_CONNECTIONS_TO_DATABASE); bcpConfig.setMaxConnectionsPerPartition(TOTAL_CONNECTIONS_TO_DATABASE); bcpConfig.setConnectionTimeoutInMs(1 * 1000); bcpConfig.setDefaultAutoCommit(false); bcpConfig.setConnectionTestStatement("select now()"); bcpConfig.setIdleConnectionTestPeriodInMinutes(5); BoneCP boneCP = new BoneCP(bcpConfig); Connection connection = boneCP.getConnection(); Statement statement = connection.createStatement(); statement.execute("select * from mytable"); } }
you should use a Jdbc Connection Pool. then from anywhere in the code that you need a connection to the database, just get a connection to the database from the pool (the Connection Pool will be in charge of maintaining the desired number of connections to your database)
for example, if you use BoneCP:
import com.jolbox.bonecp.BoneCP; import com.jolbox.bonecp.BoneCPConfig; import java.sql.Connection; import java.sql.SQLException; import java.sql.Statement; /** * <dependency> * <groupId>com.jolbox</groupId> * <artifactId>bonecp</artifactId> * <version>0.8.0.RELEASE</version> * </dependency> */ public class BoneCPexample { public static final int TOTAL_CONNECTIONS_TO_DATABASE = 20; public static void main(String[] args) throws SQLException { BoneCPexample boneCPexample = new BoneCPexample(); boneCPexample.doTheWork(); } private void doTheWork() throws SQLException { String jdbcUrlString = "jdbc:postgresql://localhost/test_database"; // jdbc:postgresql://host:port/database BoneCPConfig bcpConfig = new BoneCPConfig(); bcpConfig.setJdbcUrl(jdbcUrlString); bcpConfig.setUsername("postgres"); bcpConfig.setPassword("mi-password"); bcpConfig.setPartitionCount(1); bcpConfig.setMinConnectionsPerPartition(TOTAL_CONNECTIONS_TO_DATABASE); bcpConfig.setMaxConnectionsPerPartition(TOTAL_CONNECTIONS_TO_DATABASE); bcpConfig.setConnectionTimeoutInMs(1 * 1000); bcpConfig.setDefaultAutoCommit(false); bcpConfig.setConnectionTestStatement("select now()"); bcpConfig.setIdleConnectionTestPeriodInMinutes(5); BoneCP boneCP = new BoneCP(bcpConfig); Connection connection = boneCP.getConnection(); Statement statement = connection.createStatement(); statement.execute("select * from mytable"); } }
相关问答
更多-
将您的CSS更改为: .foto_style img { width: 50px; height:50px; } Change your CSS to: .foto_style img { width: 50px; height:50px; }
-
我应该将我的MySQL数据库连接放在PHP函数中吗?(Should I Place My MySQL Database Connection Inside A PHP Function?)[2024-02-09]
是。 这是个好主意。 我甚至把我放在一堂课上。 class database { protected $databaseLink; function __construct($mysql_db, $mysql_user, $mysql_pass, $mysql_dbName){ $this->databaseName = $mysql_dbName; $this->database = $mysql_db; $t ... -
我应该在数据库连接字符串中设置最大池大小吗?(Should I set max pool size in database connection string? What happens if I don't?)[2022-05-24]
目前您的应用程序支持池中的100个连接。 如果要将其增加到200,那么conn字符串将是什么样的 public static string srConnectionString = "server=localhost;database=mydb;uid=sa;pwd=mypw;Max Pool Size=200;"; 您可以通过在数据库中执行sp_who过程来调查应用程序使用数据库的连接数。 在大多数情况下,默认连接池大小就足够了。 Currently your appl ... -
div固定在div相对内 - 相同大小但固定更大?(div fixed inside div relative - both same size but fixed is bigger?)[2022-04-01]
固定元素的宽度是根据视口宽度计算的,而另一个的宽度是根据其父元素的宽度计算的,在这种情况下是父元素的宽度。 并且body的宽度与视口宽度不同,因为body从默认样式表中获取默认边距和/或填充 - 因此您将获取两个不同输入值的80%,因此结果也不同。 消除身体的默认边距/填充,问题就消失了: body { margin:0; padding:0; } https://jsfiddle.net/y7yc0n21/2/ The width of the fixed element is calculat ... -
您应该使用Jdbc连接池。 然后从代码中需要连接到数据库的任何地方,只需从池中获取与数据库的连接(连接池将负责维护与数据库的所需连接数) 例如,如果您使用BoneCP: import com.jolbox.bonecp.BoneCP; import com.jolbox.bonecp.BoneCPConfig; import java.sql.Connection; import java.sql.SQLException; import java.sql.Statement; /** *看了越来越多,并从下面的网址阅读下面的点后。 我尝试将“ ; Max Database Size = 1091; ”值添加到连接字符串中。 新的LocalConnectionString值现在包含正确的Max数据库容量,RDA不报告任何错误。 我假设,因为我试图操纵或添加太多属性,它不高兴。 所以最后的应对是: rda.LocalConnectionString = "Data Source=ehc.sdf;Password=xx;" + ";Max Database Size=1091;" 不 "Da ...首先, 1.)您FixedThreadPool为整个应用程序或应用程序中的特定任务创建FixedThreadPool 。 2.)部署应用程序的服务器,支持每个CPU有多少CPU,多少个线程。 3.)可能存在这样的情况,即您分配的线程数较少,而服务器具有更多,或者可能分配更多,并且您的任务不需要那么多。 它或多或少像资源的浪费。 线程池大小很少应该是硬编码的; 相反,池大小应由配置机制提供,或通过咨询Runtime.availableProcessors动态计算。 这里有详细的理解 First of all, ...所以我想出的解决了你的问题,但是当你想要在鼠标悬停在固定框(红色框)上时滚动,你无法滚动。 不太确定这是多么重要。 我添加了另一个元素,一个.holder并将你的fixed元素position: absolute; 因为你只想在你的.container里面 .container { position: relative; width:200px; height:200px; border:solid 1px black; overflow: hidden; } ...使用Small Connection池,您可以更快地访问连接表,但可能没有足够的连接来满足请求。 另一方面,对于大型连接池,有更多连接来满足请求,请求将在队列中花费更少(或没有)时间,但对连接表的访问速度较慢。 http://docs.oracle.com/cd/E19316-01/820-4343/abehs/index.html With a Small Connection pool you have faster access on the connection table but may not ...
如何使用JOOQ确定固定长度数组数据库列的大小?(How to determine size of fixed length array database column using JOOQ?)[2022-04-27]
不,jOOQ版本3.9不知道数据库阵列的任何固定大小或大小限制(既不是PostgreSQL数组类型也不是Oracle VARRAY类型)。 我已为此注册了功能请求#5932 。 No, version 3.9 of jOOQ doesn't know any fixed size or size limit of a database array (neither with PostgreSQL array types nor with Oracle VARRAY types). I have regist ...相关文章
更多- 关于mysql数据库memory表数据重复问题
- Spark - A Fault-Tolerant Abstraction for In-Memory Cluster Computing
- CLR Via C# 3rd 阅读摘要 -- Chapter 21 – Automatic Memory Management (Garbage Collection)
- POJ 3620 Avoid The Lakes【DFS水题练格式Avoid The Lakes Time Limit: 1000MS Memory Limit: 65536K Total Sub】
- 13年7月memory point
- INSERT INTO blog_appitem (user_id,appid,app_secret,is_valid) VALUES (1, 'wxf415741de036114c','48e1e345fd5f11c93af18ff1714c7f78',1)
- 用java把“真”这个字符转换为十六进制为“771f”,这是ascii还是unicode
- Hadoop格式化失败原因 Format aborted in path
- Hadoop Map/Reduce内存限制
- Guava Booleans类-布尔型基本的实用工具类
最新问答
更多- 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
- 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
- OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
- 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
- codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
- 在计算机拍照在哪里进入
- 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
- No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
- 单页应用程序:页面重新加载(Single Page Application: page reload)
- 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
- System.StackOverflow错误(System.StackOverflow error)
- KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
- 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
- android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
- TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
- 企业安全培训的各项内容
- 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
- C#类名中允许哪些字符?(What characters are allowed in C# class name?)
- NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
- 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
- 将多个行和可变行移动到列(moving multiple and variable rows to columns)
- 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
- 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
- Angular $资源不会改变方法(Angular $resource doesn't change method)
- 在Angular 5中不是一个函数(is not a function in Angular 5)
- 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
- 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
- 常见的python rpc和cli接口(Common python rpc and cli interface)
- Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
- 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)